Find the answer to your Linux question:
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2010
    Posts
    8

    Angry A "clone" doubt


    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;
    }
    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.

    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 04:43 PM. Reason: Added Code Tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •