SOURCE CODE:
#include<stdio.h>
main()
{
int pid;
pid=fork();
if(!pid)
{
printf(“ \n Child process\n ”);
printf(“ getpid(): %d\n” , getpid() );
printf(“ getppid(): %d\n” , getppid() );
}
else
{
printf(“ \n Parent process\n” );
printf(“ getpid(): %d\n” , getpid() );
printf(“ getppid(): %d\n” , getppid() );
sleep(10);
printf(“\n Parent woke up”);
}
}
OUTPUT:
[examuser35@localhost Jebastin]$ cc pc.c
[examuser35@localhost Jebastin]$ ./a.out
Child Process
getpid(): 5640
getppid(): 5639
Parent process
getpid(): 5639
getppid(): 5639
Parent woke up
EmoticonEmoticon