Last active
February 21, 2024 00:29
-
-
Save buzzsurfr/ad3d29da6324cc290a7ead4270ad38f8 to your computer and use it in GitHub Desktop.
Script to display the process IDs of docker container processes and subprocesses
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
pidlist
provided from https://superuser.com/a/384913/38868