Code for PROGRAM FOR ORPHAN PROCESS in C Programming
#include<stdio.h>
main()
{
int id;
printf("Before fork()\n");
id=fork();
if(id==0)
{
printf("Child has started: %d\n ",getpid());
printf("Parent of this child : %d\n",getppid());
printf("child prints 1 item :\n ");
sleep(10);
printf("child prints 2 item :\n");
}
else
{
printf("Parent has started: %d\n",getpid());
printf("Parent of the parent proc : %d\n",getppid());
}
printf("After fork()");
}
OUTPUT
***********
[04mca58@LINTEL 04mca58]$ cc orphan.c
[04mca58@LINTEL 04mca58]$ ./a.out
Before fork()
Parent has started: 2899
Child has started: 2900
Parent of this child : 2899
child prints 1 item :
Parent of the parent proc : 616
After fork()
[04mca58@LINTEL 04mca58]$ child prints 2 item :
After fork()