Operating System - Linux
1753814 Members
7917 Online
108805 Solutions
New Discussion юеВ

C process zombies managment

 
Fedele Giuseppe
Frequent Advisor

C process zombies managment

Hello,

I have the following problem on hp-ux 11i platform.

In a C process I trap the SIGCHLD signals and manage them in a dedicaded routine through waitpid function:

signal(SIGCHLD, SigExit);

...

void SigExit(int sig)
{
int status;
int local_pid;

....

switch(sig)
{
...

case SIGCHLD:
while ((local_pid = waitpid(-1, &status, WNOHANG)) > 0)
{
...
}
signal(sig, SigExit);
return;
break;
}
}

The children processes terminations are correclty trapped, but randomically some zombies processes are generated.

Could someone help me?

Many thanks.

Giuseppe Fedele
3 REPLIES 3
Dennis Handly
Acclaimed Contributor

Re: C process zombies managment

You may have to use sigaction(2) instead of signal(2). sigaction allows you to block the signal so you don't have multiple signals coming at the same time.

Also, the waitpid(2) says that waitpid(...,, WNOHANG) sometimes returns 0.
If it returns -1, you might want to check errno is ECHILD.
Fedele Giuseppe
Frequent Advisor

Re: C process zombies managment

Ok, thanks.

A further question: does signal function have problems in multithread environment?
Because this is my case.

Giuseppe
Dennis Handly
Acclaimed Contributor

Re: C process zombies managment

>Does signal function have problems in multithread environment?

That may explain why sigaction and blocking will fix it.