Defunct process

Andrea Temporin temporin at encopro.it
Tue Apr 13 13:59:09 UTC 2004


I'm a new user of this group, and I don't know if it's the right group for
the post, any way the situation is:
I've got a C program used as a server listening on a tcp port. At any
request from a client there is a fork. Nothing strange. My problem is that
even if I use the waitpid function i've got a lots of defunct processes.
At first I use thise code:

struct sigaction sa;
struct sigaction osa;

sa.sa_handler = Reapear;
sigfillset (&sa.sa_mask);
sa.sa_flags = SA_NOCLDWAIT;

sigaction (SIGCHLD, &sa, &osa);

and this is the Reapear function:

void Reapear(int sig)
/*--------------------------------------------------------------------------
*/
{
static int i=0;
struct sigaction sa;
struct sigaction osa;

i++;
if(i > 200)
{
while(waitpid(-1, 0, WNOHANG) >= 0);
i = 0;
}

sa.sa_handler = Reapear;
sigfillset (&sa.sa_mask);
sa.sa_flags = SA_NOCLDWAIT;

sigaction (SIGCHLD, &sa, &osa);
}

I had the same problem on a Solaris system and resolved it using the
sigaction function (the old version used signal function), but it seems not
to have any effect on REDHAT 7.1 linux servers. Unfortunately I didn't wrote
the original code and so I've just found out that I had to change signal
into sigaction with the right structure as parameters but I don't understan
completely what Reapear function does...
Anyone can help me?
Than you very much
Andrea






More information about the redhat-list mailing list