Return to the archive index

Re: fork in cgi script

From: Tom Christiansen <tchrist@mox.perl.com>
Date: 20 Jun 1996 03:11:27 GMT
Newsgroups: comp.lang.perl.misc,comp.infosystems.www.authoring.cgi

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    Igor Keselman <Igor.Keselman@ab.com> writes:
:Hi everyone.
:I'have a script that takes the input from a form and does some lengthy
:computation. The user who submitted the form doesn't need to see the 
:results of the computations. So, to save the waiting time for the user
:I tried to fork a child process in which I would do all the time
:consuming stuff, and in the main prooess I would just thank the user
:and tell him to go home. But it doesn't seem like I'm saving any time.
:My question is, "Is that the way things work, I mean, does all processes
:have to exit before the message "Contacting host...etc/etc/etc.." goes 
:away and the browser stops?"

Kinda.  You have to close all connections back to the
remote system in the forked child, which usually means reopening
STDIN and STDOUT to something more useful:

    open(STDIN,  "</dev/null")
	|| die "can't open STDIN to /dev/null: $!";

    open(STDOUT, ">/dev/null")
	|| die "can't open STDOUT to /dev/null: $!";

There may even be other file descriptor leaks in some servers.

--tom
-- 
Tom Christiansen      Perl Consultant, Gamer, Hiker      tchrist@mox.perl.com

    "With a PC, I always felt limited by the software available.  
    On Unix, I am limited only by my own knowledge." 	--Peter J. Schoenster 

From John's Useful Posting Archive (JUPA)
Maintained by John Callender
John's Home Page

Archive created with babymail