【问题标题】:unix script to collect the thread dump logs of a process用于收集进程的线程转储日志的 unix 脚本
【发布时间】:2012-05-14 06:30:09
【问题描述】:

我正在尝试生成有关 HashMap.put 函数的问题。我编写了一个测试代码,它将运行 100 多个线程。通过使用 jstack 或 kill 我能够获得特定线程的线程转储我的进程..问题是我无法立即捕获线程转储,我希望将所有线程转储记录在一个文件中,直到进程结束。有没有可以编写的 linux 命令或 shell 脚本来执行此操作?

【问题讨论】:

  • 将你的代码输出重定向到一个文件并'kill -3'它?

标签: linux bash thread-dump jstack


【解决方案1】:
#!/bin/bash

if [ $# -eq 0 ]; then
    echo >&2 "Usage: jstackSeries  [ <count> [ <delay> ] ]"
    echo >&2 "    Defaults: count = 10, delay = 1 (seconds)"
    exit 1
fi

pid=$1          # required
count=${2:-10}  # defaults to 10 times
delay=${3:-1} # defaults to 1 second

while [ $count -gt 0 ]
do
    jstack $pid >jstack.$pid.$(date +%H%M%S.%N)
    sleep $delay
    let count--
    echo -n "."
done

参考这里:

http://howtodoinjava.com/2012/12/19/how-to-get-thread-dump-in-linux-using-jstack/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-22
    • 2011-07-04
    相关资源
    最近更新 更多