[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Small Process Killing Question
On Tue, Jan 16, 2001 at 08:28:54PM -0700, Kenneth Ingham wrote:
> You do not need to reboot to get rid of zombies. They occur when the
> parent does not wait(2) (or waitpid(2)) for them. Using ps, find the
> parent process ID (PPID) and kill *it*. Then init will inherit the
> zombies and clean them up.
Perhaps I can add some example to the conversation.
A ps -axl output shows 3 (of really 128) zombied childs with random pids and
a parent process id of 21098 which after forking is forced to sleep forever
and never wait (hence all these little zombies).
1000 204 21098 0 28 20 0 0 - Z+ p5 0:00.00 (forkb)
1000 445 21098 0 28 20 0 0 - Z+ p5 0:00.00 (forkb)
1000 503 21098 0 28 20 0 0 - Z+ p5 0:00.00 (forkb)
After killing the parent the init process inherets the crying orphaned zombie
childs and reaps them out of their ill misery (I just love writing that
sentence).
> kill -9 21098 ; ps axl |grep forkb | head
1000 162 24191 0 28 20 504 0 - RV p1 0:00.00 grep forkb
Here is the source code of my example:
----
int
main(void)
{
int i = 128;
pid_t pid;
for (; i ; i--) {
switch(pid = fork()) {
case -1:
fprintf(stderr, "couldn't fork: %s\n", strerror(errno));
exit(1);
case 0:
sleep(10);
exit(0);
}
}
/* forked 128 times children are dead and we don't care what happens to
* us we just loop forever
*/
for(;;) sleep(1);
}
----
Cheers,
--
- -
Peter Philipp <pjp@daemonium.com>
Daemonium