Re: Problem with killing zombie processes
From: Gordon Burditt (gordonb.dsl5o_at_burditt.org)
Date: 05/03/05
- Previous message: Bernd Haug: "Re: Q: How to Set up A Daily E-Mail Reminder?"
- In reply to: Xarky: "Problem with killing zombie processes"
- Next in thread: Bjorn Reese: "Re: Problem with killing zombie processes"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 03 May 2005 15:53:36 -0000
>I am writing a client/server program. The server is being implemented
>as a concurrent server(using the fork), where it handles multiple
>clients simultaneously.
>
>Now what I require, is that when a client closes up a connection with
>the server, the process that was handling the client is terminated and
>cleaned up from the system.
>
>At the begining of the program, I am calling the following:
>(void) signal(SIGCHLD, kill_dameon);
A SIGCHLD signal handler needs to call wait(), or one of its variants,
to bury the child.
>
>The kill_dameon method, that clears up zombie processes is the
>following:
>void kill_dameon(int sig)
>{
> pid_t pid;
> int data;
>
> data = 1;
> if (pid == -1)
> error_msg();
>
> printf("Cleared a zombie process.\n");
>} // end method kill_dameon
>
>Now when client and server programs are exectued, when the first
>client terminates, the message(Cleared a zombie process.\n) given in
>method is shown on server. When the second, third, etc client
>terminates, that message is not given any more.
>
>I added this line "(void) signal(SIGCHLD, kill_dameon);" at the end of
>the kill_dameon method, but when did this, after first client
>terminates, an infinite loop of that message was made.
SIGCHLD is given not for a child dying, but for having a dead,
unburied, child. If you don't call wait() or one of its variants
in the signal handler, it will loop. If you want to make absolutely
sure you don't pause waiting for a child, use wait3() or wait4()
with the WNOHANG option.
Gordon L. Burditt
- Previous message: Bernd Haug: "Re: Q: How to Set up A Daily E-Mail Reminder?"
- In reply to: Xarky: "Problem with killing zombie processes"
- Next in thread: Bjorn Reese: "Re: Problem with killing zombie processes"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|