Hi, Thanks for the reply,
Indeed our code solves the problem but not efficiently. Your have to iterate over all running processes in order to filter the child processes. I wondered if there is a possibility to directly get the child processes. anyway thanks, Yaron Kahanovitch ----- Original Message ----- From: "Paul Lalli" <[EMAIL PROTECTED]> To: beginners@perl.org Sent: Wednesday, July 11, 2007 4:06:14 PM (GMT+0200) Auto-Detected Subject: Re: How to get a list of child processes (Unix systems only) 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/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/