src/parallel: family_pids were incompatible with FreeBSD 7 and CentOS 3.

This commit is contained in:
Ole Tange 2013-03-23 14:33:12 +01:00
parent e14d8f9586
commit 3d26864477

View file

@ -3519,42 +3519,30 @@ sub family_pids {
# TODO test this on different OS as 'ps' is known to be different # TODO test this on different OS as 'ps' is known to be different
my $self = shift; my $self = shift;
my $pid = $self->pid(); my $pid = $self->pid();
my $script; my (@pidtable,%children_of,@pids);
if ($^O eq 'linux') { if ($^O eq 'linux' or $^O eq 'solaris') {
$script = q{ # Table with pid parentpid (SysV + GNU)
family_pids() { @pidtable = `ps -ef | awk '{print \$2" "\$3}'`;
for CHILDPID in `ps --ppid "$@" -o pid --no-headers`; do
family_pids $CHILDPID &
done
echo "$@"
}
} .
"family_pids $pid; wait";
} elsif ($^O eq 'solaris') {
$script = q{
family_pids() {
if [ -z "$1" ] ; then return ; fi
family_pids `pgrep -P "$*"` &
for CHILDPID in "$@"; do
echo $CHILDPID
done
}
} .
"family_pids $pid; wait";
} else { } else {
# This should cover all System V-derived flavors of 'ps' # Table with pid parentpid (BSD)
$script = q{ @pidtable = `ps -o pid,ppid -ax`;
family_pids() {
for CHILDPID in `ps -f | awk '$3 == '"$@"' {print $2}'`; do
family_pids $CHILDPID &
done
echo "$@"
}
} .
"family_pids $pid; wait";
} }
my @pids = qx{$script}; for (@pidtable) {
chomp(@pids); /(\S+)\s+(\S+)/ or ::die_bug("pidtable format");
push(@{$children_of{$2}},$1);
}
my @more = ($pid);
while(@more) {
my @m;
push @pids,@more;
for my $parent (@more) {
if($children_of{$parent}) {
push @m, @{$children_of{$parent}};
}
}
@more = @m;
}
return (@pids); return (@pids);
} }