Forking processes from cgi...

Forking processes from cgi...

Post by jasqu.. » Tue, 13 Jun 2000 04:00:00


I was wondering if there was a way to fork a
program so that I get a status page back and
let the program I forked continue with it's job.

My reason: I'm trying to put together a web
interface for mkhybrid/ cdrecord. A kind of web-
toast for my local intranet.

Many thanks,

Sent via
Before you buy.


Forking processes from cgi...

Post by Nick K » Wed, 14 Jun 2000 04:00:00

Quote:> Hi!

> I was wondering if there was a way to fork a

Erm - try the FAQ.

Quote:> My reason: I'm trying to put together a web
> interface for mkhybrid/ cdrecord.

Why a Web interface?  What does it gain you over xcdroast?

Nick Kew


1. Problems forking a background process from CGI

I'm trying to write a CGI script that forks a process to do some
time-consuming calculations and mail the results out when done.  The
recipient's e-mail address is taken from an input form.

Here's the central routine (for testing purposes, a sleep() call and a
silly message have been substituted for the actual calculation)

sub do_work {

    local($address) = &untaint($taintedaddr);
    unless ($address) {
        print "<EM>$taintedaddr is not a valid e-mail address!</EM>";
    if ($pid = fork) { # we get here if we're the parent
        print "<H1>Background Process Launched</H1>\n";
        print "The work is being performed in the background.\n";
        print "The results will be sent to $address when completed.";
    } else  {  
        # we get here if we're the child in the background
        close STDOUT;   # server seems to want this
        sleep 10;       #substitute for "lengthy work"
        open (MAIL, "| $MAIL -s 'script results' $address");
        print MAIL "The results are in!\n";
        print MAIL "2 + 2 = 4!\n";
        close MAIL;
        exit 0;

The thing is, it works fine on a Sun Sparc10.  The routine returns
immediately and the background process is spawned, waits 10 seconds,
then mails out the message.  On the target Linux system, however
(kernel 1.1.85), the background process goes into suspended state and
never sends the mail out.  I have to manually kill it.

Can anyone tell me what the background process is waiting for?  I've
tried closing STDIN and STDERR as well as STDOUT, but to no avail.
The same problem occurs if I just write to a file instead of piping to

When I run the script from the command line instead of from the HTTP
server (NCSA httpd 1.3) it works OK.

Thanks much for thinking about this.


Lincoln D. Stein                Whitehead Institute/MIT Genome Center


2. NEC 260 CD-ROM

3. Safely forking long perl process in CGI

4. MIME charset

5. fork and exec server process from a cgi

6. HELP! compile FVWM on SUN

7. Why <defunct> process after leaving a fork()ed process?

8. Charlotte unix users group

9. passing stdin to a forked process, after writing some data to the process ..

10. forked child process remains in process table

11. starting daemon from cgi/cgi process that is a daemon

12. /cgi-bin/phf /cgi-bin/test-cgi /cgi-bin/handler

13. comsat forking, forking and forking (3.2.0)