in reply to Doing a system command and getting the pid

It'd be nice if you gave us what you had tried. It really does help. Anyway ... Off the top of my head, untested:

FORK: { if (my $child = fork()) { print "Child process ID: $child\n"; } elsif (not defined $child) { # failed to fork. next FORK; } else { # child. open(STDOUT, '>somefile); close(STDIN); # just good practice for background procs exec($program, @program_args); } }
Update: Fixed the off-by-everything error as noted by Eimi Metamorphoumai - thanks!

Replies are listed 'Best First'.
Re^2: Doing a system command and getting the pid
by Eimi Metamorphoumai (Deacon) on Jan 21, 2005 at 00:41 UTC
    I think you've got your if backwards. fork returns zero to the child, and gives the parent the child's pid, so you want to do your exec in the case that $child is 0 (but defined).