Skip to content

Instantly share code, notes, and snippets.

@cuiwm
Forked from theirix/pstack-osx.sh
Created November 1, 2018 07:36
Show Gist options
  • Save cuiwm/69f9bcc032d1a6c5f2e3c0d8b6d22dec to your computer and use it in GitHub Desktop.
Save cuiwm/69f9bcc032d1a6c5f2e3c0d8b6d22dec 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