DCPM: fork oddness

Alex Charrett alex at dclug.org.uk
Mon Nov 25 19:03:30 CST 2002

Hi all,

I'm having an odd issue with fork maybe you guys can shed some light on.
I've got a constantly running process that forks itself when doing time
consuming tasks to make the front end script more responsive.  It's
doing it's job nicely and I've got an exit(0) to get the child to
terminate at the correct time. 

However, the exit is causing defunct processes to sit in the process
list until the parent exits (which I don't want it to do as the parent
isn't meant to exit).

You can re-create the problem with this test fork script:


while (1) {


if($child_pid == 0) {
        print "ooh, I\'m the child\!\n";


and an excerpt from my ps ax (this is on linux btw):

 2949 pts/2    S      0:00 /usr/bin/perl ./fork2.pl (this is the parent)
 2950 pts/2    Z      0:00 [fork2.pl <defunct>]
 2951 pts/2    Z      0:00 [fork2.pl <defunct>]
 2954 pts/2    Z      0:00 [fork2.pl <defunct>]
 2956 pts/2    Z      0:00 [fork2.pl <defunct>]
 2957 pts/2    Z      0:00 [fork2.pl <defunct>]

Any ideas?


More information about the Devoncornwall-pm mailing list