Zombie Process:
On Unix and Unix-like computer operating systems, a Zombie process or defunct process is a process that has completed execution but still has an entry in the process table. This entry is still needed to allow the parent process to read its child's exit status
#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
#include<sys/wait.h>
int main()
{
int id ,x ,y;
id=fork();
if(id==0)
{
x=getpid();
y=getppid(); // in this progtamme first parent execute then child. in parent sleeping for 15ms and child for 5 ms. in 5 ms child process finish so it create zombie process
printf("Child process 1>PID:%d child 2>PPID:%d\n",x,y);
sleep(5);
printf("\nchild terminated\n");
}
else{
x=getpid();
y=getppid();
printf("Parent process 1>PID:%d parent 2>PPID:%d\n",x,y);
sleep(15);
//wait(&id);
printf("\nparent terminated\n");
}
return(0);
}
Output:
Parent process 1>PID:5307 parent 2>PPID:2588
Child process 1>PID:5308 child 2>PPID:5307
child terminated
parent terminated