in reply to How do I get the process ID from a system("x &") call?

This code works nicely... :)
print "About to fork:\n"; my $pid = fork(); if ($pid ==0) { exec "sleep 5"; exit(0); } else { print "Child PID: $pid\n"; } print "Parent continuing...\n";


----
Zak
"There is no room in this country for hyphenated Americanism" ~ Theodore Roosevelt (1915)

Replies are listed 'Best First'.
Re: Re: How do I get the process ID from a system("x &") call?
by zakzebrowski (Curate) on Sep 19, 2002 at 18:08 UTC
    Update -- zombie processes never die... See fork man page for details...
    my $pid = fork(); if ($pid ==0) { unless(fork){ print "Child launched!\n"; exec"/bin/sleep 10"; # server process exit 0; } exit 0; } waitpid($pid,0); $pid=$pid+1; // cheating process ids are 1+ what we think they a +re print "Child PID: $pid\n"; push @pidArray, $pid; }
    Thanks guys!

    ----
    Zak
    "There is no room in this country for hyphenated Americanism" ~ Theodore Roosevelt (1915)