Consider this example -
#include<stdio.h> #include<stdlib.h> #include<unistd.h> int main() { pid_t pid = fork(); if (pid > 0) { printf("Child pid is %d\n", (int)pid); sleep(10); system("ps -ef | grep defunct | grep -v grep"); } return 0; } In this example, the child process remains a zombie until the parent process terminates. How did this zombie process get cleaned up without being reaped by any process ?
$ ./a.out Child pid is 32029 32029 32028 0 05:40 pts/0 00:00:00 [a.out] <defunct> $ ps -p 32029 PID TTY TIME CMD