Skip to content

Instantly share code, notes, and snippets.

@theirix
Created April 7, 2015 08:39
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save theirix/ceacb52b1e5cf1a9594a to your computer and use it in GitHub Desktop.
Save theirix/ceacb52b1e5cf1a9594a to your computer and use it in GitHub Desktop.
pstack for osx
#!/bin/sh
#
# Script prints gdb stack of the process with a specified pid
if [ -z $1 ]; then
echo "Usage: $0 pid"
exit 1
fi
PID=$1
BINARY=`ps -o comm= -p $PID`
SCRIPT_DIR=`dirname $0`
if [ -z "$BINARY" ]; then
echo "Cannot determine binary"
exit 1
fi
TMPFILE=`mktemp -t pstack.XXXXXX` || exit 1
trap "rm -f $TMPFILE" exit
echo "thread apply all bt\ndetach\nquit" > $TMPFILE
/usr/bin/gdb -q -x $TMPFILE "$BINARY" $PID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment