in reply to Detached forking in a CGI script

I'm not sure fork is the right tool here. I recently came across an easy to use module to put things in the background, Proc::Background that may help (cross-platform even).

use warnings; use strict; use Proc::Background; my @cmd = qw(perl sleep.pl); my $proc = Proc::Background->new(@cmd); my $pid = $proc->pid; print "*** $pid ***\n";

Output showing parent exits while proc still running:

~/scratch$ perl proc.pl *** 3489 *** ~/scratch$ ps ax | grep sleep 3489 pts/1 S 0:00 perl sleep.pl

Replies are listed 'Best First'.
Re^2: Detached forking in a CGI script
by queldor (Acolyte) on Apr 29, 2016 at 17:49 UTC

    Looking at Proc::Background, it appears to use fork and exec.

    So I would say that Fork the correct tool for the job

      Pedantic..., I'll rephrase... "this job appears much easier when using a known-working module that shadows what you want to do in the background, with a nice, clean API".

      Out of curiosity, what working suggestions do you have? ;)

        Oh, I completely agree w/ using a clean API, which I would say Proc::Background is.

        I personally try to stick to the KISS mentally