Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

don't wait for a system call to finish running

Status
Not open for further replies.

keak

Programmer
Sep 12, 2005
247
CA
Hi there,
From within perl, I am running a command that takes quite long to complete (loger than apache's http timeout)

I have something like $result = `./script1 arg1 arg2`
The thing is, I just want my cgi to continue without waiting for this line (script1) to finish processing.

I did $result = `./script1 arg1 arg2 &` but that didn't hlep. Is there a method to tell perl to just start off the script1 process and continue onwards without its completion?

 
I found a method that forks a child process (If I have my script run in the child process segment, I get instantaneous reply from the browser the parent process output, but then, the browser still waits for the child process to finish.

Is there any way I can complete this http request and leave teh child process running on its own even after the parent returns (since the child takes long time to complete)

Code:
defined (my $kid = fork) or die "Cannot fork: $!\n";
if ($kid) {
    parent process code goes here
}
else  {
    child process code goes here
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top