rpike has asked for the wisdom of the Perl Monks concerning the following question:

I have a CGI Perl application whereby I need to run a totally separate perl script (just a behind the scenes utility script). This application will be running on both Windows and also on Unix/Linux as well. I don't need to reference the process ID or exchange information of any sort - the program will just start up and, the important thing, is the parent should not have to wait to continue on as the 2 programs running will be totally independent of each other. I was using system until I noticed that the parent script was waiting for the child to finish. A straight forward, simple snippet of code would be most appreciated. Thank you in advance.

Replies are listed 'Best First'.
Re: Independent Worker Process
by BrowserUk (Patriarch) on Dec 22, 2017 at 18:17 UTC

    Be aware: if you spawn a process from a cgi process, you will need to close stdin, stdout & possible stderr, in the child immediately it runs as they will usually inherit those from the parent, and the webserver waits for them to close before ending the session.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
    In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit
Re: Independent Worker Process
by karlgoethebier (Abbot) on Dec 22, 2017 at 18:01 UTC

    Execute another program but don't wait. might help. Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Re: Independent Worker Process
by poj (Abbot) on Dec 23, 2017 at 08:30 UTC
Re: Independent Worker Process
by Anonymous Monk on Dec 26, 2017 at 13:56 UTC
    Modules like Parallel::ForkManager are very handy for this kind of needs-to-be-portable logic. If the two processes are intended to be children of the parent, the parent will have to wait for both of them to finish, because the children will be reaped when it does finish. Consider using the daemon/service facilities that are available (differently ...) in each environment, as an alternative to spawning them as children of an otherwise do-nothing parent., and especially if the children are intended to be long-lived.