in reply to apache2 and system

What you'll actually want to do is something more like:
my $pid = fork; die "Error forking: $!" unless defined $pid; if (!$pid) { my $pid = fork; die "Error forking: $!" unless defined $pid; if (!$pid) { exec("/path/to/foo"); } else { CORE::exit; } }

There are two important things in that:

Anyway, hope that helps.

------------ :Wq Not an editor command: Wq

Replies are listed 'Best First'.
Re^2: apache2 and system
by sgifford (Prior) on Sep 28, 2004 at 02:59 UTC
    The shell launched by system doesn't seem to wait for the background process to complete, at least not in my tests. If the OS has an setsid shell command, is there any advantage of using fork and exec over just:
    system('setsid sleep 1000 &');
    It seems to work here.

    Also, the OP may want to think about what to do with open filehandles. It's possible the effects of having a second copy of STDOUT open by the child process will cause strange behavior (like never seeing EOF on a pipe/socket to that filehandle). Redirecting to /dev/null would solve that: system('setsid sleep 1000 </dev/null >/dev/null 2>/dev/null &');

      You're totally right, I spoke before I tested <smacks self>.

      It's easy enough to see if you just do something like:

      perl -e 'system("sleep 10")'
      which returns imediately. I must have been thinking about something else. (Particularly, I think I was thinking of some recent question in which someone wanted the exit status of the backgrounded process... and that's not at all the same issue... oh, well)
      ------------ :Wq Not an editor command: Wq
Re^2: apache2 and system
by water (Deacon) on Sep 28, 2004 at 01:46 UTC
    many thanks. could that helpful code snippet go onto a mason page inside apache2 w/o ill effect?