Re: CGI script: release browser after spawning new process
- From: xhoster@xxxxxxxxx
- Date: 17 May 2005 20:36:58 GMT
"Prachi" <prachi.shah@xxxxxxxxx> wrote:
> The purpose of this cgi script is to receive cgi parameters from a user
> filled form and pass them along as command line parameters to another
> perl script that should run the computation in the background. I used
> perl exec because it spawns this new process and does not return.
>
> -----
> my $command = 'perl RunComputation.cgi ';
> foreach my $cgi_param ($q->param) {
> if ($q->param($cgi_param) && $q->param($cgi_param) ne ' ') {
> if($cgi_param =~ /check\d+/) {
> my @vals = $q->param($cgi_param);
> foreach my $v (@vals) {
> $command .= $cgi_param.'="'.$v.'" ';
> }
> } else {
> $command .= $cgi_param.'="'.$q->param($cgi_param).'"
> ';
> }
> }
> }
> exec $command;
> -----
>
> The new process spawns well and the scripts behave as excepted, except
> that while this child process is executing the browser stays active and
> keeps loading.
You haven't spawned a new process, you have transformed into a different
program (but still the same "process" from unix's perspective).
You have to close STDOUT and STDERR, that way the server knows
the process is done talking to it. However, common servers will
kill the cgi process once they are done with it, so your process may
get killed early. You need a fork to protect from this.
> I want to release the browser (or provide an explicit
> end of cgi command, whatever is possible) as soon as this background
> process starts.
> Is that possible?
fork, and then the parent should exit normally, and the child
should close (or reopen) STDOUT and STDERR and then exec (or just proceed
to do whatever needs doing by itself).
fork and exit;
open STDERR, ">>log/whatever";
close STDOUT;
#do whatever needs to be done;
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
.
- Follow-Ups:
- References:
- Prev by Date: Can a perl script monitor another?
- Next by Date: Permuting using any number of given chars
- Previous by thread: Re: CGI script: release browser after spawning new process
- Next by thread: Re: CGI script: release browser after spawning new process
- Index(es):
Relevant Pages
|
|