Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Detached forking in a CGI script

by flexvault (Monsignor)
on Apr 29, 2016 at 18:22 UTC ( #1161897=note: print w/replies, xml ) Need Help??

in reply to Detached forking in a CGI script


    I need the script to fork a child process and to get hold of the pid of this child, but to then not make the parent (the CGI process) wait for the child, and allow it to exit immediately.

A few years back and this process was easy, but today many of the web servers will not allow children to continue to run if the parent exits. I've gotten around this by using a continuous running Perl script that keeps checking a file for instructions on work to be passed to new forked script.

The cgi script locks the file, adds the work to be done to that file, and then closes (which unlocks also) the file and exits.

The continuous running script sees the new work and forks to do the required work. (Note: You can also use 'pre-forked' scripts to do this.)

Possibly the referenced module does something similar and may give a more complete solution than using your own 'fork'. Just because it uses 'fork' and 'exec' doesn't mean that there isn't a whole lot more logic necessary to provide independent processes to complete the work after the parent cgi script exits. YMMV


"Well done is better than well said." - Benjamin Franklin

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2022-01-28 19:38 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (73 votes). Check out past polls.