in reply to How do you get PID of a program called using system call?
#!/usr/bin/perl -wT use strict; %ENV = (); # clean out the %ENV hash to prevent mischief $ENV{PATH} = '/bin'; my @pids; # array for storing childr +ens pids my $cmd = 'sleep 2; echo "I am child $$"'; # command children will ex +ecute for (1..4) { my $childpid = fork() or exec($cmd); # fork off a child push(@pids,$childpid); # store the childs pid in @pid +s } print "My Children: ", join(' ',@pids), "\n"; waitpid($_,0) for @pids; # wait for children to finish print "Children are done\n";
-Blake
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: How do you get PID of a program called using system call?
by gbarr (Monk) on Oct 08, 2001 at 17:22 UTC | |
by blakem (Monsignor) on Oct 08, 2001 at 23:36 UTC |