Skip to content

Instantly share code, notes, and snippets.

@dillonhicks
Created March 5, 2021 02:54
Show Gist options
  • Select an option

  • Save dillonhicks/4d26bfc7a3c92ee017d040e355ee74a8 to your computer and use it in GitHub Desktop.

Select an option

Save dillonhicks/4d26bfc7a3c92ee017d040e355ee74a8 to your computer and use it in GitHub Desktop.
Get a stacktrace of all running containers
#!/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