Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

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;

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://73088]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2018-05-25 00:36 GMT
Find Nodes?
    Voting Booth?