in reply to Re: getting a child's process ID
in thread getting a child's process ID
Hope this helps you.#!/usr/bin/perl -w use strict; our $Parent_PID = $$; # ... Many interesting lines of code ... my $pid; # The mini-loop below will re-attempt the fork() # in case of errors, that are usually transient # resource shortages. You might not want to do this # in your scenario... while (($pid = fork()) < 0) { sleep 5; } if ($pid) { # Father print "father: the child is $pid\n"; # ... Interesting code to wait for the children ... } else { # Child print "child: My parent is $Parent_PID\n"; print "child: I am $pid (or $$)\n"; }
|
|---|