Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/sh
set -eu
pids=$(ps -eHo pid,ppid \
| awk -vpid="$1" '
BEGIN { pids[pid] }
$1 in pids || $2 in pids {
print $1
pids[$1]
}
')
ps -Ho pid,ppid,comm,args $pids
# ps -Ho pid,ppid,comm,args $(ps -eHo pid,ppid | awk -vpid="$1" 'BEGIN { pids[pid] } $1 in pids || $2 in pids {print $1; pids[$1]}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment