Unix Programming - Problem with killing zombie processes

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > May 2005 > Problem with killing zombie processes





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Problem with killing zombie processes
Xarky

2005-05-03, 6:00 pm

Hi,

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);

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.

What could my problem be?
Can someone help me out please.
Thanks in Advance
Gordon Burditt

2005-05-03, 6:00 pm

>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
Bjorn Reese

2005-05-03, 6:00 pm

Xarky wrote:

> 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.


See section 1.6 of the FAQ:

http://www.erlenstar.demon.co.uk/unix/faq_2.html#SEC13

--
mail1dotstofanetdotdk
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com