Use pgrep
instead:
pgrep -g 18322
From man pgrep
:
-g, --pgroup pgrp,... Only match processes in the process group IDs listed. Process group 0 is translated into pgrep's or pkill's own process group.
Alternatively, you can just parse the ps
output in simpler ways:
ps xh -o pgrp,pid | awk '$1==18322'
Or just simplify your (needlessly complex) original Perl approach:
ps xh -o pgrp,pid | perl -lane 'print $F[1] if $F[0] eq 5592'
Or just grep
:
ps xh -o pgrp,pid | grep -Po '\s*5592\s*\K.+'