This question is also posted on StackOverflow

I have this very simple Perl script on my linux server.

What I would like to be able to do is to call the script from a browser on a separate machine
Have the script initiate a fork ->
Have the parent send an httpResponse -> (freeing up the browser)
Immediately end the parent ->
Allow the child to do its job, heavy complex database work, which could take a minute or two ->
Have the child end itself with no output whatsoever

When I call this script from a browser, the browser does not receive the sent response till the child is complete.

Yes, it works when called from the command line.

Is what I want to do possible?
p.s. I even tried it with Proc::Simple->start, but I get the same hangin up.

#!/usr/bin/perl local $SIG{CHLD} = "IGNORE"; use lib '/var/www/cgi-bin'; use CGI; my $q = new CGI; if(!defined($pid = fork())) { die "Cannot fork a child: $!"; } elsif ($pid == 0) { print $q->header(); print "i am the child\n"; sleep(10); print "child is done\n"; exit; } else { print $q->header(); print "I am the parent\n"; print "parent is done\n"; exit 0; } exit 0;

In reply to Can I have a Perl script, initiated from a browser, fork itself, and not wait for the child to end? by bartender1382

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.