I have some Perl scripts that I use to run automated jobs.  I launch the CGI
scripts with through a web browser and I use Apache.  The scripts worked
correctly with perl 5.00503, but when I upgraded to perl 5.6.1, the scripts
do not work the same.  The Apache version is 1.3.12.  My server is running
RedHat 6.1, linux kernel 2.2.12-20.

I have 3 scripts, parent.pl, child.pl and grandchild.pl.  They are in
/home/httpd/cgi-bin.  I have simplified the scripts for testing. With a web
browser I go the url
http://myserver/cgi-bin/parent.pl?job=test&title=testrun.  I stop the
browser after I went to that url (I do not wait for it to timeout).
Parent.pl execs to child.pl.  Child.pl forks and then execs to
grandchild.pl.  Grandchild.pl just sleeps forever.  With perl 5.00503, when
I do 'ps auxw' on the server I would see the pids for child.pl and
grandchild.pl.  With perl 5.6.1, about 10 minutes after the scripts started,
when I do 'ps auxw' on the server, I no longer see the child.pl pid.  I need
the pid for child.pl because I have another script that polls the system for
that pid to verify the script is still running and notifies me when it
stops.

I have changed the timeout setting in the Apache conf file
(/etc/httpd/conf/httpd.conf).  It defaults to 300 seconds, but I tried
changing it from 10 all the way to 100000.  I still get the same results.
About 10 minutes after the browser session ends, the pid for child.pl
disappears.

Is there any way to resolve this?  Did anything change if fork or exec in
5.6.1?

Thanks in advance,
Andy

Here's the 3 scripts:

parent.pl
-------------
#!/usr/bin/perl
use CGI_Lite;

my ($cgi, $data, @task);

$cgi     = new CGI_Lite ();
$data    = $cgi->parse_form_data ();
$task[0] = $$data{'job'};
$task[1] = $$data{'title'};


print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>Dummy Test</TITLE>";

exec '/home/httpd/cgi-bin/child.pl',  @task;

print "</BODY></HTML>";
exit 0;
-------------


child.pl
-------------
#!/usr/bin/perl

my ($p1, $p2);
$p1 = $ARGV[0];
$p2 = $ARGV[1];

RunProcess('/home/httpd/cgi-bin/grandchild.pl') ;

# RunProcess: Similar to the "system()" call, only this code does not block
# certain signal handling such as SIGINT, SIGHUP, SIGQUIT giving us the
ability
# to kill the process (without turning into a zombie) if we "system" out
# another script/binary.
sub RunProcess(@)
{
    my $ProgramName = shift(@_);
    my @Arguments = @_;
    my $pid = 0;
    my $ChildPid = 0;
    my $length = 0;

    # (Striped this code out of Programming Perl by O'Reilly & Assoc., Inc)
    if ( $pid = fork ) { # fork
        # Parent process
        $ChildPid = $pid;
        push @childPidList, $ChildPid;
        waitpid $ChildPid, 0;
        @childPidList = RemoveElement( $ChildPid, @childPidList );
    } elsif (defined $pid) { #Child
        # Child Process
        sleep 10 ;
        unless (exec $ProgramName, @Arguments)

            print "Failed to 'exec $ProgramName @Arguments'\n";
            exit 0;
        }
    } else {
        print "Couldn't Fork, continuing";
        return 0;
    }
    return 1;
}


sub RemoveElement($@)
{
    my $id = shift(@_);
    my @list = @_;
    my $count = 1;
    my $listLength = $#list + 1;

    foreach $item ( @list ) {
        if (( $item == $id ) && ( $count <= $listLength )) {
            splice( @list, $count-1, 1, splice( @list, $count ) );
        }
        $count++;
    }
    return @list;
}

-------------


grandchild.pl
-------------
#!/usr/bin/perl

while (1) {
    sleep 5 ;
}


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to