in reply to thread inside mod_perl handler will never been released

Your father should wait for your child, otherwise the child might become a zombie... Brrrrr.

see : fork

If you really want the father to resign his soon, hence letting the son dying alone, consider the following code:

#! /usr/bin/perl # # Playing with processes ... use POSIX qw(setsid); if ( $pid = fork()){ print "I am the father..\n"; print " Child pid : $pid \n"; } else{ setsid(); close STDIN ; # Inside a web server close STDERR ; # Idem close STDOUT ; # Idem print "\nI am the child \n"; print "I am $$\n"; $timer= 30 ; sleep($timer); print "\nWahhh, i am awake after $timer seconds \n"; } exit 0 ;
Hope it helps.

-- Nice photos of naked perl sources here !

Replies are listed 'Best First'.
Re^2: thread inside mod_perl handler will never been released
by earlati2 (Beadle) on Jul 27, 2006 at 13:40 UTC

    Using setsid and exit I got extra httpd daemon at each fork.

    So it doesn' seem a good solution

    If I use Core::exit(0) instead of exit I got an httpd daemon in zombie state.

    $pid = fork(); if( $pid == 0 ) { setsid(); # ----------------------------------------- close STDIN; close STDOUT; close STDERR; # ----------------------------------------- my $p_pid; $p_pid = getppid; ae_util::mylog( "START Child process: $$.$p_pid " ); sleep 1; ae_util::mylog( "EXIT Child process: $$.$p_pid " ); # CORE::exit(0); exit; }

    I found another solution which is more simple and seems to works well:

    $SIG{CHLD} = 'IGNORE';

    and

    $pid = fork(); if( $pid == 0 ) { # ----------------------------------------- close STDIN; close STDOUT; close STDERR; # ----------------------------------------- my $p_pid; $p_pid = getppid; ae_util::mylog( "START Child process: $$.$p_pid " ); sleep 1; ae_util::mylog( "EXIT Child process: $$.$p_pid " ); CORE::exit(0); }

    Do you known if that solution ( ignore SIGCHLD signal ) have some drawback ?

    Edited by planetscape - changed pre to code tags; added rudimentary formatting