Created
July 11, 2019 07:21
-
-
Save ryul99/f2f1e2d7fdcf1b5918e51f2f4d2cc536 to your computer and use it in GitHub Desktop.
get pids of descendants processes of docker container and itself
This file contains hidden or 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 | |
# get docker container self and descendants pids | |
docker_container_pids=() | |
docker_container_descendants=() | |
for container_id in $(docker ps --format '{{.ID}}'); do | |
a=$(docker inspect -f '{{.State.Pid}}' "$container_id") | |
docker_container_pids+=( "$a" ) | |
done | |
for pid in ${docker_container_pids[@]}; do | |
for descendant in $(pstree -p $pid | grep -o '([0-9]\+)' | grep -o '[0-9]\+'); do | |
docker_container_descendants+=( "$descendant" ) | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment