Skip to content

Instantly share code, notes, and snippets.

@x-yuri
Last active March 28, 2020 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save x-yuri/b1293c8829343c84965f829e79cdfbbb to your computer and use it in GitHub Desktop.
Save x-yuri/b1293c8829343c84965f829e79cdfbbb to your computer and use it in GitHub Desktop.
#!/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