/* C program to demonstrate Zombie Process.Child becomes Zombie as parent is sleepingwhen child process exits.*/
#include
<stdlib.h>
#include
<sys/types.h>
#include
<unistd.h>
int
main()
{
// Fork returns process id
// in parent process
pid_t child_pid = fork();
// Parent process
if (child_pid > 0) {
sleep(100);
}
// Child process
else {
sleep(50);
exit(0);
}
return 0;
}
Output:
Neelkanth_98$ ps -elf | grep a.out
0 S labuser 28903 28022 0 80 0
- 1052 hrtime 21:12 pts/1 00:00:00 ./a.out
1 Z labuser 28904 28903 0 80 0
- 0 exit 21:12 pts/1 00:00:00
[a.out] <defunct>
0 S labuser 29099 29073 0 80 0 -
3990 pipe_w 21:13 pts/7 00:00:00 grep --color=auto a.out