Results 1 to 1 of 1
Code:
include<stdio.h>
#include<sched.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
int fn(void *a)
{
int *p;
printf("Value of a is = %d",*p);
printf("\n");
return 0;
}
int main()
{
int *i,a=125;
pid_t child;
printf("\n ...
- 10-02-2011 #1Just Joined!
- Join Date
- Aug 2010
- Posts
- 8
A "clone" doubt
In the above program, In function "fun()" the first printf statement (i.e, printing the value of a) is not printing anything in the screen. If i give the second printf(simply a new line) i'm getting the output.Code:include<stdio.h> #include<sched.h> #include<stdlib.h> #include<unistd.h> #include<sys/types.h> int fn(void *a) { int *p; printf("Value of a is = %d",*p); printf("\n"); return 0; } int main() { int *i,a=125; pid_t child; printf("\n This is parent with id : %d",getppid()); i=(int*)malloc(100*sizeof(int))+100; child=clone(&fn,i,CLONE_PARENT,&a); printf("\n Got the child id as : %d",child); return 0; }
1. can anyone explain me why?
2. My friends are telling that I should not use "printf", if I create a process by using "clone()". They are telling me to use "write()" instead.
If they are telling the correct answer, also explain me why I should not use printf in clone?Last edited by MikeTbob; 10-02-2011 at 03:43 PM. Reason: Added Code Tags


Reply With Quote