mirror of
https://git.savannah.gnu.org/git/parallel.git
synced 2024-11-29 09:27:56 +00:00
src/parallel: family_pids were incompatible with FreeBSD 7 and CentOS 3.
This commit is contained in:
parent
e14d8f9586
commit
3d26864477
54
src/parallel
54
src/parallel
|
@ -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 "$@"
|
|
||||||
}
|
}
|
||||||
} .
|
for (@pidtable) {
|
||||||
"family_pids $pid; wait";
|
/(\S+)\s+(\S+)/ or ::die_bug("pidtable format");
|
||||||
|
push(@{$children_of{$2}},$1);
|
||||||
}
|
}
|
||||||
my @pids = qx{$script};
|
my @more = ($pid);
|
||||||
chomp(@pids);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue