Robert Citek wrote:

> 
> Hello all,
> 
> getppid returns the parent process ID given a processes ID.  Is there a
> corresponding function which returns a list of child processes IDs?
> 
> I could do an external system call to ps or pstree, but thought perhaps
> something internal to perl might already exist.  I've Googled, but haven't
> found anything yet.

take a look at the Proc::ProcessTable module, no need to shell out for 
external sys call:

#!/usr/bin/perl -w
use strict;

use Proc::ProcessTable;

#--
#-- we will ignore the child
#--
$SIG{CHLD} = 'IGNORE';

#--
#-- create 5 child processes for demo purpose. arrange them so they stay
#-- long enough so we can find them later
#--
for(1..5){
        sleep(10) and exit if(fork == 0);
}

#--
#-- list all process running in your machine and find all 
#-- child process
#--
for my $p (@{new Proc::ProcessTable->table}){
        print $p->pid," child of $$\n" if($p->ppid == $$);
}

__END__

prints:

21099 child of 21098
21100 child of 21098
21101 child of 21098
21102 child of 21098
21103 child of 21098

perldoc Proc::ProcessTable

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to