Skip to content

Instantly share code, notes, and snippets.

@buzzsurfr buzzsurfr/watchpids.sh
Last active Feb 12, 2019

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

buzzsurfr commented Feb 12, 2019

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
You can’t perform that action at this time.