Saturday, August 13

Create a Child process and print process-id


(i) Using one fork() system call

#include<stdio.h>
main()
{
      int f,c,p;
      f=fork();
      if(f==0)
      {
              c=getpid();
              printf("Child Process\n pid: %d",c);
              c=getppid();
              printf("\tppid :%d \n",c);
      }
      else if(f>0)
      {
           sleep(1);
           c=getpid();
           printf("\nParent Process\n pid: %d",c);
           c=getppid();
           printf("\tppid :%d\n\n",c);
      }
}
     
     
     
     

0 comments :

Post a Comment