Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: CGI and System

by eclark (Scribe)
on Feb 18, 2005 at 22:01 UTC ( #432538=note: print w/replies, xml ) Need Help??

in reply to CGI and System

Wrap your head around this. It forks away from the cgi, detaches the child process and execs your command. If you're just running a perl script, you can replace the system call with a function you want to run in the background.

use strict; use POSIX 'setsid'; my $command = q{perl -e 'sleep 30'}; if (my $pid = fork) { exit; } elsif (defined $pid) { open STDIN, '/dev/null'; open STDOUT, '>/dev/null'; open STDERR, '>/dev/null'; setsid(); unless (exec $command) { die "Couldn't run process!"; } } else { die "Cannot fork: $!"; }

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2022-05-24 03:44 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (82 votes). Check out past polls.