pstack: Input/output errorfailed to read target.

修改 /usr/bin/pstack

#!/bin/bash

if test $# -ne 1; then
    echo "Usage: `basename $0 .sh` <process-id>" 1>&2
    exit 1
fi

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

# GDB doesn't allow "thread apply all bt" when the process isn't
# threaded; need to peek at the process to determine if that or the
# simpler "bt" should be used.

backtrace="bt"
if test -d /proc/$1/task ; then
    # Newer kernel; has a task/ directory.
    if test `/bin/ls /proc/$1/task | /usr/bin/wc -l` -gt 1 2>/dev/null ; then
        backtrace="thread apply all bt"
    fi
elif test -f /proc/$1/maps ; then
    # Older kernel; go by it loading libpthread.
    if /bin/grep -e libpthread /proc/$1/maps > /dev/null 2>&1 ; then
        backtrace="thread apply all bt"
    fi
fi

GDB=${GDB:-/usr/bin/gdb}

if $GDB -nx --quiet --batch --readnever > /dev/null 2>&1; then
    readnever=--readnever
else
    readnever=
fi

# Run GDB, strip out unwanted noise.
$GDB --quiet $readnever -nx /proc/$1/exe $1 <<EOF 2>&1 |
$backtrace
EOF
/bin/sed -n \
    -e 's/^(gdb) //' \
    -e '/^#/p' \
    -e '/^Thread/p'
 

pstack是一个用于在Linux系统上获取进程调用栈的工具。它可以帮助我们了解进程的运行状态,识别进程中的性能瓶颈和异常情况。pstack输出的内容包括进程的调用栈信息,每个线程的信息,以及每个函数调用的堆栈信息。 下面是pstack输出的一般格式: ``` PID: 1234 Command: /path/to/command Thread 1 (Thread ID: 12345): #0 0x00007f2b1e9eac51 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0 #1 0x0000000000400891 in thread_func (arg=0x0) at thread.c:20 #2 0x00007f2b1e9e2aa1 in start_thread () from /lib64/libpthread.so.0 #3 0x00007f2b1d7b1ead in clone () from /lib64/libc.so.6 Thread 2 (Thread ID: 12346): #0 0x00007f2b1e9e2eaf in pthread_join () from /lib64/libpthread.so.0 #1 0x000000000040094b in main (argc=1, argv=0x7fff45a0b9f8) at main.c:21 ``` 其中,PID是进程的ID号,Command是进程的命令行。每个线程的信息包括线程ID和调用栈信息。调用栈信息是一个堆栈跟踪,它列出了当前正在执行的函数调用序列。每行输出包含以下信息: - #n:是当前堆栈中的第n层函数调用。 - 0xaddress:是当前执行的函数的地址。 - function_name():是当前执行的函数的名称和参数。 - file_name:line_number:是包含当前执行的函数的源代码文件名和行号。 pstack的输出可以帮助我们了解程序的执行情况,尤其是在程序出现崩溃、死锁或性能瓶颈等问题时,可以使用pstack来定位问题所在,进而进行调试和优化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值