Created
March 5, 2021 02:54
-
-
Save dillonhicks/4d26bfc7a3c92ee017d040e355ee74a8 to your computer and use it in GitHub Desktop.
Get a stacktrace of all running containers
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
| #!/usr/bin/env bash | |
| # | |
| # usage: sudo ./docker-stacktrace.sh | |
| # | |
| # will generate multiple files in the form gdb-<PID>.<EXENAME>.txt in the cwd for each running container | |
| # | |
| stacktrace-for-pid() { | |
| local pid=$1 | |
| local name="$(basename $(readlink /proc/${pid}/exe))" | |
| local command_file=/tmp/${pid}.gdb | |
| cat <<EOF > ${command_file} | |
| set pagination off | |
| set logging file gdb-${pid}.${name}.txt | |
| set logging on | |
| attach ${pid} | |
| bt full | |
| detach | |
| quit | |
| EOF | |
| gdb -x ${command_file} | |
| } | |
| main() { | |
| set -x | |
| local pids=($(docker inspect $(docker ps -q) | jq '.[].State.Pid')) | |
| for pid in "${pids[@]}"; do | |
| stacktrace-for-pid "${pid}" | |
| done | |
| } | |
| main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment