Why or how does killing the parent process clean the zombie child processes in linux?
4
votes
2
answers
1134
views
Consider this example -
#include
#include
#include
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]
$ ps -p 32029
PID TTY TIME CMD
Asked by shawdowfax1497
(123 rep)
Dec 31, 2021, 12:18 AM
Last activity: Dec 31, 2021, 01:42 AM
Last activity: Dec 31, 2021, 01:42 AM