Run a background process in cgi script.

Run a background process in cgi script.

Post by Apyo s.r.o » Wed, 20 May 1998 04:00:00



I have a problem with cgi programming- I want a cgi script to start a
background process and finish.
I've got two scripts:

dontwait:

#! /bin/sh
wait.pl &
echo "Content-type: text/html"
echo
echo "Ok"
#############

and wait:

#! /usr/bin/perl
for (i=1;i<=200000;i++) {
#do a lot of computations
g=sqrt(2);

Quote:}

###########

When I start the dontwait script from the shell it exits immediately while
wait does it's computations. But when I start dontwait as a cgi-script:
http://localhost/cgi-bin/dontwait it doesn't exit until wait finishes. How
should I force dontwait to exit as soon as it starts wait?

 
 
 

Run a background process in cgi script.

Post by Barry Margoli » Wed, 20 May 1998 04:00:00




>When I start the dontwait script from the shell it exits immediately while
>wait does it's computations. But when I start dontwait as a cgi-script:
>http://localhost/cgi-bin/dontwait it doesn't exit until wait finishes. How
>should I force dontwait to exit as soon as it starts wait?

Are you sure the script isn't exiting?  Or is it just that you don't get an
immediate response from the web server?

The web server is presumably waiting until the pipe between it and the CGI
script is closed before it closes the connection to the browser.  Since the
background process still has its stdout connected to the pipe, it won't
close until the background process completes.

If you have the background process close all its file descriptors, or
execute it with something like:

wait.pl </dev/null >/dev/null 2>&1 &

then you shouldn't have to wait for it.

--

GTE Internetworking, Powered by BBN, Cambridge, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.

 
 
 

1. Help: cgi script and background process

I am using httpd 1.4.1, and Tcl to write cgi scripts.  I have discovered
that the cgi scripts always wait for all subprocesses to finish before
it returns to the client browser, regardless of whether the subprocess
is spung into background (with the & operator) or not.

These background processes of mine are generating HTML reports for the
user to see later, and are taking a long time to finish.  Therefore, I
wish to write a script that would spung off these subprcesses into
background, and immediately returns without waiting for them to finish.
However, I am having trouble doing this.  The httpd server always waits,
background or not.

Is there a way to tell the server not to wait for background processes?
If not, then is there a way to at least present partial output to the
user waiting on the client browser, to inform him/her about current
status?

Thanks for any light you can shed on this.

S.C. Chang

2. Release of DejaGnu 1.1.1

3. (newbie) how to make script running in background process?

4. Newbie help: SunOS and solaris

5. ftp shell script that runs as a background process with progress monitor for user?

6. startx mesg: Cannot allocate colormap entry

7. Apache: "Couldn't spawn child process" running CGI script

8. root or not to root

9. Killing csh background process **AND** any unfinished processes (fg and background) it started

10. Process id of process started in "background" from script

11. apache: give /home/mailman/cgi-bin permissions to run cgi-scripts.

12. Running cgi scripts outside /cgi-bin directory

13. Problems forking a background process from CGI