kill -3无法输出java堆栈信息,使用jstack
2013-04-12 11:26
761 查看
Redirect thread dump to another file?
On Jboss or Tomcat application server, we usually use kill -3 PID to get thread dump to default STDOUT which is catalina.out under $Tomcat_Home/logs folder. It might be nature to use commandkill -3 PID > some.file 2>&1 to try to redirect the thread dump info to some.file than default one. However, it will not work. The reason is kill is just a command to send a signal to a process. You are redirecting the output of the kill command
itself rather than the process (what the process does upon receipt of a signal is separate), so the redirect (supposed to kill command itself) has no effect on which file the process (PID) will write to. Given that, if we need redirect thread dump for that
process to some other file, we need add redirects to that process when it starts.
Another popular way is to use jstack -F PID to get the whole thread dump forcefully."jstack": A JVM troubleshooting tool that prints stack traces of all running threads of a given JVM process, a Java core file, or remote debug
server. It comes with
JDK so it is free too. :-)
jstack
If installed/available, we recommend using the jstack tool. It prints thread dumps to the command line console.To obtain a thread dump using jstack, run the following command:
jstack
You can output consecutive thread dumps to a file by using the console output redirect/append directive:
jstack >> threaddumps.log
jstack script
Here's a script, taken fromeclipse.org that will take a series of thread dumps using jstack.
#!/bin/bash
if [ $# -eq 0 ]; then
echo >&2 "Usage: jstackSeries [ [ ] ]"
echo >&2 " Defaults: count = 10, delay = 0.5 (seconds)"
exit 1
fi
pid=$1 # required
user=$2 # required
count=${3:-10} # defaults to 10 times
delay=${4:-0.5} # defaults to 0.5 seconds
while [ $count -gt 0 ]
do
sudo -u $user jstack -l $pid >jstack.$pid.$(date +%H%M%S.%N)
sleep $delay
let count--
echo -n "."
done
Just run it like this:
sh jstackSeries.sh [pid] [cq5serveruser] [count] [delay]
For example:
sh jstackSeries.sh 1234 cq5serveruser 10 3
http://linuxhelp4u.blogspot.com/2011/04/redirect-thread-dump-to-another-file.html
相关文章推荐
- 如何用Jstack把java进程中的堆栈信息输出到文件
- 输出java进程的jstack信息示例分享 通过线程堆栈信息分析java线程
- cpu高占用,线程堆栈,jstack,pstack,jmap, kill -3 pid,java(weblogic,tomcat)
- JAVA 程序中Log4j输出详细错误堆栈信息
- Java 基础小知识一: 使用ResourceBundle 和 MessageFormat 实现国际化信息输出
- java---使用日志输出信息的方法
- java自带的工具Jstack截取进程中的堆栈信息
- 在Java代码中输出html的信息使用out.println()
- 使用日志框架如何输出printStackTrace()的堆栈信息
- jstack查看Java堆栈信息
- java中使用ReentrantLock锁中的Condition实现三个线程之间通信,交替输出信息
- Java多线程--使用ThreadMXBean 打出堆栈信息
- 在AIX上用IBM的JVM,内存溢出时默认地会产生javacore文件(关于cpu的)和heapdump文件(关于内存的)。手动产生堆栈文件的方法是使用kill -3
- 使用java面向对象创建动物类并输出动物信息
- 使用log4j的时候如何输出printStackTrace()的堆栈信息
- Oracle EBS无法启动,错误信息:您的安全设置已组织自签名的应用程序使用已过期的Java版本运行。
- Win下,通过Jstack截取Java进程中的堆栈信息
- 使用log4j的时候如何输出printStackTrace()的堆栈信息
- 使用log4j的时候如何输出printStackTrace()的堆栈信息
- Java 输出 printStackTrace 堆栈信息