Re: CGI script: release browser after spawning new process



"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
.



Relevant Pages

  • Re: Running system() commands in background
    ... qazmlp wrote: ... > I have to run the command in the background? ... > prefer the user to see what is happening when the perl script is being ... I'm not sure fork will work under win32. ...
    (comp.lang.perl.misc)
  • Re: when does ssh return?
    ... can't seem to figure out how to use ssh to start a command on a remote ... and a similar thing with a perl script that forks. ... the perl script fork, have its child fork, and then the grandchild ...
    (SSH)
  • when does ssh return?
    ... I've looked through ssh man page and FAQ and tried a google search, but can't seem to figure out how to use ssh to start a command on a remote machine, have ssh exit immediately, and still have the command running on the remote machine. ... and a similar thing with a perl script that forks. ... the perl script fork, have its child fork, and then the grandchild ...
    (SSH)
  • Re: Can you duplicate Standard Output WITHOUT tee command?
    ... run where he wanted to catch stdout. ... Yes, this is a difficult command pipe, especially as written it uses ... The last file descriptor operations restore the normal meaning of stdin ...
    (comp.unix.shell)
  • Re: Howto parse stdout without changing it
    ... > I would like to parse stdout from a command list but also piped stdout to ... I guess you are looking for `tee`. ... echo "gzip result: $" ...
    (comp.unix.shell)