[Tutor] Handling SIGCHLD signal to kill zombie processes

rafael.sousa rafael.sousa at netcabo.pt
Wed Dec 3 14:02:27 EST 2003


Hi!

I need to know what to write in a function that handles the SIGCHLD signal, in order to kill zombie processes that are left running.

-> In C ANSI, what I do is start by specifying what function is going to handle the signal:

signal(SIGCHLD, handleSIGCHLD);

and then one handler that does the trick is:

void handleSIGCHLD() {
   int stat;

   /*Kills all the zombie processes*/
   while(waitpid(-1, &stat, WNOHANG) > 0);
}

-> In Python, specifying the handler is easy:

import signal
signal.signal(signal.SIGCHLD, handleSIGCHLD)

What I don't know how to do is an equivalent to the C function above...

Can anyone help?

Thanks in advance,

Rafael Sousa



More information about the Tutor mailing list