Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Starting a new process (fork?)

by repson (Chaplain)
on Apr 17, 2001 at 14:17 UTC ( #73088=note: print w/ replies, xml ) Need Help??


in reply to Starting a new process (fork?)

Instead of relying on the shell background metacharacter like ColtsFoot does, you can use the perl fork function.

use CGI ':standard'; my $pid = fork; if ($pid == 0) { # we are the child close; # close all filehandles so server won't try to stay open exec 'backupprogram' or exit ; # transfer execution } elsif ($pid) { # we are the original process print header, start_html, 'Backup initiated. You can close this window at any time', end_html; } else { die "Fork failed: $!\n"; } # something went wrong
You could write that as:
fork==0 and exec 'backupprogram'; print header,start_html,'etc...'
But that wouldn't be as reliable.

Update: Remembered close behaviour wrongly, that line should read
close STDOUT; close STDERR; close STDIN;


Comment on Re: Starting a new process (fork?)
Select or Download Code
Replies are listed 'Best First'.
Re: Re: Starting a new process (fork?)
by suaveant (Parson) on Apr 17, 2001 at 17:51 UTC
    close; # close all filehandles so server won't try to stay open
    Not a big deal, bit this only closes the currently selected filehandle... which is usually STDIN, though I think that's all you need to close for the httpd to be happy.
                    - Ant

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://73088]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (14)
As of 2015-07-30 13:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (271 votes), past polls