in reply to Re: apache2 and system
in thread apache2 and system

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 &');

Replies are listed 'Best First'.
Re^3: apache2 and system
by etcshadow (Priest) on Sep 28, 2004 at 03:09 UTC
    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