1836836 Members
2144 Online
110110 Solutions
New Discussion

Re: Zombies

 
Namit
Advisor

Zombies

This problem is more about programming in HP-Unix

If I do a signal(SIGCLD, SIG_IGN), then I assume that any signal sent from the child will be ignored and I don't even have to do a waitpid() or anything.

Now I read that on some systems there's no way to prevent signal handlers from being automatically reset to SIG_DFL when the signal handler gets called.

Does that mean that if my application hits a part of code that is handling some other signals like signal(SIGINT,...), then the application will stop ignoring the signals from the children also ?
Live and let die
6 REPLIES 6
Armin Feller
Honored Contributor

Re: Zombies

Hi,

yes, it seams so. Zombie processes are created when the parent process either does not wait on the child process, or does not ignore the child's termination by setting the 'SIGCLD, SIG_IGN' signal within their program. Zombies remain until the parent exits. Although zombies do not use CPU time, they do occupy a slot in the process table.

Zombie processes are also created when a child process completes, and sends a termination to the parent, before the parent receives the 'SIG_IGN, SIGCLD' signal to ignore the termination.

These processes cannot be killed, as they are already dead. If the parent is killed before it exits properly, and cleans up any zombie child processes, only a reboot will clear the zombies from the system.

Refer to these documents for additional information:

- /usr/share/doc/proc_mgt.txt
- signal man page
- signal(5) man page

Regards ...
Armin
Stanimir
Trusted Contributor

Re: Zombies

Hi!
Interesting question! So I've created and compiled some applications on HPUX 10.20&11.0,
Linux Red Hat and SunOS 5.7, including:

"signal(SIGCLD, SIG_IGN)"

without any problem.
Which system you have troubles with?
So if you find such problem on any system,
I suppose you can use another technic -
with wait()-function in exit of child.
Regards,Stan
Dietmar Konermann
Honored Contributor

Re: Zombies

This kind of uncertainty is one of the reasons not to use the legacy signal() functions. Using the POSIX.1 sematics of sigaction() guarantees that the specified action remains active until changed again explicitely.

Richard Stevens' "Advanced Programming in the UNIX Environment" is a great book covering all those things. Recommended!

Best regards...
Dietmar.
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
Adam J Markiewicz
Trusted Contributor

Re: Zombies

Hi.

One more comment to Dietmar.
You're absolutelly right, however sigaction() is quite complicated and if you want to know what's going on you have to check every flag descriptpion carefully.
For simple tasks, especially to the people that know signal() syntax the sigset() function is the best choice in my opinion.

And one more word to Armin:
I'm not a HP specialist, but according to my knowledge of Unix systems whenever a processes' parent gets killed, the process itself is automatically 'adopted' by 'init' proces (pid=1). So if it is a zombie, its return value should be read by the 'init' (and that process certainly waits() for its children) causing the zombie to disappear.

However, as I said, it can be somewhat different on HP.

Good luck

Adam
I do everything perfectly, except from my mistakes
Juan Manuel López
Valued Contributor

Re: Zombies

Hi.
On my experience, only reboot can kill the zombies process.
I am sorry, so is the only way.

Juanma.
I would like to be lie on a beautiful beach spending my life doing nothing, so someboby has to make this job.
Adam J Markiewicz
Trusted Contributor

Re: Zombies

Hi Juan

But have you ever tried killing the parent?
Just because I was curious I did a simple test, wich I've checked with gdb and ps command:


#define _INCLUDE_POSIX1C_SOURCE
#include
#include
#include

int main( void )
{
switch( fork() ) {
case 0:
break; //child-terminate
case -1:
puts( "fork() failed" );
break;
default: // parent-don't wait()
{
sigset_t ss;
int sig;
sigemptyset( &ss );
sigaddset( &ss, SIGINT );
puts( "Waiting for SIGINT" );
sigwait( &ss, &sig ); // this is not removing any zombie
break;
}
}

return 0;
}

And what do you say - after sending SIGINT to the parent my zombie was gone.

Good luck

Adam
I do everything perfectly, except from my mistakes