On Jul 11, 2:47 am, [EMAIL PROTECTED] wrote: > I am looking for an efficient way to get list of child (forked) processes of > a given processes id. > Has anyone idea how to do it in "pure perl style" ?
This information is stored in Process Table for the system. You can access this table using the Proc::ProcessTable module, available on CPAN. For example: #!/opt2/perl/bin/perl use strict; use warnings; use Proc::ProcessTable; #create some children: my @children; for (1..3) { my $pid = fork(); if ($pid == 0) { #child sleep(60); exit; } else { #parent push @children, $pid; } } #While kids are asleep, investigate: my $t = Proc::ProcessTable->new(); my @proc_kids = map { $_->pid() } grep { $_->ppid() == $$ } @{$t->table()}; print "I ($$) forked off these kids: @children\n"; print "Process table says $$'s kids are: @proc_kids\n"; #Interrupt each kid's nap, and wait kill 2, @children; for (1..3) { wait(); } __END__ $ ./proc.pl I (191) forked off these kids: 192 193 194 Process table says 191's kids are: 193 192 194 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/