Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: fork and zombies

by Somni (Friar)
on Oct 24, 2007 at 06:51 UTC ( [id://646836]=note: print w/replies, xml ) Need Help??


in reply to fork and zombies

There's only one reason you ever get zombies: you were supposed to wait on a child process after it died, and you didn't. Given you're calling waitpid it means you either haven't gotten to that part of your code, or it's sitting there waiting on one pid that isn't ready.

If you truly don't care what your child processes return, just set $SIG{CHLD} = "IGNORE". If you do care, then you should setup an actual signal handler, $SIG{CHLD} = sub { my $pid = wait; $exits{$pid} = $?; }, or something similar.

Waiting on a specific pid is usually only done when you know that specific process has died.

Also, foreach my $pid (@pids) { ... }, you don't need a C-style for loop to iterate over an array.

Replies are listed 'Best First'.
Re^2: fork and zombies
by wolfger (Deacon) on Oct 24, 2007 at 16:52 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://646836]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (8)
As of 2024-04-23 08:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found