#!/bin/bash 
if (( $# < 1 )) 
then 
    echo "usage: `basename $0` pid" 1>&2 
    exit 1 
fi

if [[ ! -r /proc/$1 ]] 
then 
    echo "Process $1 not found." 1>&2 
    exit 1 
fi

backtrace="bt" 
if [[ -d /proc/$1/task ]] 
then 
    if [[ `ls /proc/$1/task 2>/dev/null | wc -l` > 1 ]] 
    then 
        backtrace="thread apply all bt" 
    fi  ; 
elif [[ -f /proc/$1/maps ]] 
then 
        if grep -e libpthread /proc/$1/maps > /dev/null 2>&1 
    then 
                backtrace="thread apply all bt" 
        fi 
fi

GDB=gdb

$GDB -quiet -nx /proc/$1/exe -p $1 <<<"$backtrace" | 
    sed -n  \ 
    -e 's/^(gdb) //' \ 
    -e '/^#/p' \ 
    -e '/^Thread/p'

使用方法

pstack.sh pid

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-02
  • 2021-06-25
  • 2021-06-20
  • 2021-09-30
  • 2022-03-08
  • 2021-09-06
猜你喜欢
  • 2021-09-18
  • 2021-06-24
  • 2021-12-17
  • 2022-12-23
  • 2021-09-25
  • 2021-07-22
相关资源
相似解决方案