You are on page 1of 2

/* 4.

orphan process */
#include <sys/types.h> #include <unistd.h> #include<stdio.h> main() { int pid; pid=fork(); if(pid==0) { printf("\n I am the child, my process ID is %d ",getpid()); printf("\n I am the child's parent process ID is %d ",getppid()); sleep(10); printf("\n I am the child, my process ID is %d ",getpid()); printf("\n I am the child's parent process ID is %d ",getppid()); } else { printf("\n I am the parent, my process ID is %d ",getpid()); printf("\n I am the parent's parent process ID is %d ",getppid()); } }

OUTPUT

I am the child, my process ID is 5301 I am the parent, my process id is 5300 I am the parent's parent, my process ID is 5129 [it2-21@localhost ~]$ I am the child's parent, my process ID is 5300 I am the child, my process Id is 5301 I am the child's parent, my process ID is 1

You might also like