Tuesday, 4 November 2014

Fork system call

#include<stdio.h>
#include<unistd.h>
main()
{
int pid;
pid =fork();
if(pid==0)//execute child process only and pid<0 for execution of parent process alone
{
printf("%d\n",getpid());//process id of child
printf("%d\n",getppid());//process id of child's parent
}
else
{
printf("%d\n",getpid());
printf("%d\n",getppid());//parent process id parent
}
}

verify id using command >ps -el

No comments:

Post a Comment