Skip to content

Instantly share code, notes, and snippets.

@buzzsurfr
Last active February 21, 2024 00:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buzzsurfr/ad3d29da6324cc290a7ead4270ad38f8 to your computer and use it in GitHub Desktop.
Save buzzsurfr/ad3d29da6324cc290a7ead4270ad38f8 to your computer and use it in GitHub Desktop.
Script to display the process IDs of docker container processes and subprocesses
#!/bin/bash
pidlist() {
local thispid=$1
local fulllist=
local childlist=
childlist=$(ps --ppid $thispid -o pid h)
for pid in $childlist
do
fulllist="$(pidlist $pid) $fulllist"
done
echo "$thispid $fulllist"
}
dockerpids() {
local fulllist=
local dockerpids="$(pidof docker-containerd-shim)"
for p in ${dockerpids}
do
for q in $(ps --ppid $p -o pid h)
do
fulllist="$(pidlist $q) $fulllist"
done
done
echo "$fulllist"
}
ary=($(dockerpids))
DOCKER_PIDS=${ary[@]}
ps -Ho etime,pid,ppid,user,cmd --pid ${DOCKER_PIDS// +/,} 2> /dev/null
@buzzsurfr
Copy link
Author

pidlist provided from https://superuser.com/a/384913/38868

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment