Hi and thank you. I've tried the script sample and it works fine but it doesn't work with the following line: fork && exit;
I need to type just: fork; .... because otherwise the browser (IE) keeps "Opening page...". Can you tell me, is it OK if I use the script with the line for closing STDIN, STDOUT, and STDERR uncommented? In this case all works fine. Is it any danger to create zombies? And what do you recommend, to use exec, or system? I don't need to get the output from the child process, but I don't know how is better, to let the parent process to wait for the child, or not. Thank you. Teddy's Center for the blind: http://teddy.fcc.ro/ Email: [EMAIL PROTECTED] ----- Original Message ----- From: "zentara" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, September 30, 2002 3:17 PM Subject: Re: How to run a process in background? On Sun, 29 Sep 2002 16:40:07 +0200, [EMAIL PROTECTED] (Octavian Rasnita) wrote: >I want to make a script that is activated from a browser but it might take a >long time to send all the messages using the Net::SMTP. > >So I think that it could be a good idea to make a background process to run >it. > >Can you give me some hints about how I should use the fork, to run the >process in background? Your biggest problem is to close the pipes to apache from the forked children, else your clients will see their browser's hang. Merlyn has a good column on this at www.stonehenge.com column 20. Here is a simple example to demonstrate the problem. Make up some long process to test this with, like while(1){sleep(1)} Then try running it as a cgi script with and without the line which closes STDOUT, STDIN, and STDERR. With it commented out, your browser will hang. ############################################################## #!/usr/bin/perl use warnings; use strict; $| = 1; # need either this or to explicitly flush stdout, etc. # before forking print "Content-type: text/plain\n\n"; print "Going to start the fork now\n"; fork && exit; #try running with the following line commented out close STDOUT;close STDIN;close STDERR; exec('./fork-long-process-test-process') || warn "funniness $!"; #if you use system here, instead of exec, the parent process #hangs around for child to exit, even though the cgi exits. ############################################################# -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]