1

I have written a server in perl, waiting for tcp connections. Every time the server receives one, it forks a new child in charge of it and continues listening for another connection.( And so it cannot wait for the SIGCHILD. ) The child does what it is supposed to do and exits, but continues to "live" as a zombie. What is the solution please ?

babak
  • 11
  • 2

1 Answers1

5

Set $SIG{CHLD} = 'IGNORE'; to have the system handle them for you automatically.

Or set $SIG{CHLD}to a subroutine and waitpid:

use POSIX qw( WNOHANG );

$SIG{CHLD} = sub {
    while( ( my $child = waitpid( -1, WNOHANG ) ) > 0 ) {
        print "SIGNAL CHLD $child\n";
    }
};

If you really want to understand how it works (of course you do! :), you should read perlipc

There is also more info here on Stack Overflow

Community
  • 1
  • 1
grebneke
  • 4,414
  • 17
  • 24