mirror of
https://git.savannah.gnu.org/git/parallel.git
synced 2024-12-26 06:37:56 +00:00
src/parallel: family_pids were incompatible with FreeBSD 7 and CentOS 3.
This commit is contained in:
parent
e14d8f9586
commit
3d26864477
56
src/parallel
56
src/parallel
|
@ -3519,42 +3519,30 @@ sub family_pids {
|
|||
# TODO test this on different OS as 'ps' is known to be different
|
||||
my $self = shift;
|
||||
my $pid = $self->pid();
|
||||
my $script;
|
||||
if ($^O eq 'linux') {
|
||||
$script = q{
|
||||
family_pids() {
|
||||
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";
|
||||
my (@pidtable,%children_of,@pids);
|
||||
if ($^O eq 'linux' or $^O eq 'solaris') {
|
||||
# Table with pid parentpid (SysV + GNU)
|
||||
@pidtable = `ps -ef | awk '{print \$2" "\$3}'`;
|
||||
} else {
|
||||
# This should cover all System V-derived flavors of 'ps'
|
||||
$script = q{
|
||||
family_pids() {
|
||||
for CHILDPID in `ps -f | awk '$3 == '"$@"' {print $2}'`; do
|
||||
family_pids $CHILDPID &
|
||||
done
|
||||
echo "$@"
|
||||
}
|
||||
} .
|
||||
"family_pids $pid; wait";
|
||||
# Table with pid parentpid (BSD)
|
||||
@pidtable = `ps -o pid,ppid -ax`;
|
||||
}
|
||||
my @pids = qx{$script};
|
||||
chomp(@pids);
|
||||
for (@pidtable) {
|
||||
/(\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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue