My issue is related to using fork()
within Perl code.
I wish to fork a new process and capture its PID and return it back to the callee program. Is there some command in Perl which would make this possible?
views:
272answers:
4
+4
A:
Well, Perl's fork
function returns PID
of child to parent and 0 to child, isn't that what you want?
Michael Krelin - hacker
2009-09-17 11:40:01
+5
A:
my $pid = fork();
if ($pid == 0)
{
# We are the child.
}
elsif defined($pid)
{
# We are the parent of child with PID=pid
}
else
{
# The fork failed
}
David Sykes
2009-09-17 13:22:22
'We are the proud parent ...' unless the child was stillborn...there's a third path - if $pid is undef.
Jonathan Leffler
2009-09-17 14:03:56
Updated, thanks
David Sykes
2009-09-18 07:16:17