Hi,

I have the following problem.

I run a perl script that set up an environment, then
Run a tool and wait for its return.

But the tool hangs from time to time. I have to kill it when it hangs.

To do  this, I use Fork. I fork a child process that will run the  tool.
In the parent process, I get the child process's pid and if it runs longer
than a set time limit, the parent will kill the child.

But I found out that while the child dies, it still hangs around with the
tool. (it has (perl) when I do 'ps -xc' ).

If I kill the tool process, then thing is ok.

I could not figure out how to get the tool process's id. But by observing,
I notice that its pid is 'always' equals to child process's pid+1.

So, I let the parent process kills 'child pid"+1. It seems to work so far.

I have to admit I don't feel comfortable with doing this, though it works so
far.

Any suggestion on how I could figure out the tool's pid?

Regards,

Ted Zeng
Adobe Systems Inc.

Here is the part of the script that does fork:

if(!defined( $kidpid = fork() )){
    die "Canot fork: $!";
    }elsif ($kidpid == 0) {
        ## Execute the Eggplant Scripts.
        execEggplant();
    } else {
    my $count=0;
    my $tConstant = 120; ## 20 min.
    do {
        sleep 10;
        $count ++;
        $kid = waitpid(-1, WNOHANG);
        } until ($kid > 0 or $count > $tConstant);
        if($count > $tConstant ){
        {
                $kidpid = $kidpid + 1; ## get the Eggplant PID
            ## The child process is still running. Log and kill it.
                my $ret = `kill $kidpid`;
                LogBoth("...20 min. passed... We terminate the Eggplant
process: $ret");   
                exit(0); ## no need to archive now. The child process should
do the archive
        }
            ##
        }
    }

Reply via email to