jstack:目标进程没有响应

发布于 2024-12-04 08:36:54 字数 1191 浏览 0 评论 0原文

我正在运行 Ubuntu 服务器版本,我想获取 Tomcat 的线程转储。

所以,我首先尝试找出tomcat使用的是哪个PID:

$ jps -l
5809 sun.tools.jps.Jps

但是它不存在?

因此,我改用 top 并找到了 PID 5730。

然后我调用 jstack 来获取线程转储:

$ sudo jstack -l 5730
5730: Unable to open socket file: target process not responding or HotSpot VM not loaded
The -F option can be used when the target process is not responding

发生了什么事? :-(

我已经尝试按照 Jstack 中所述导出 CATALINA_TMPDIR 和Jstat 停止升级到 JDK6u23,但这没有改变任何内容:

$ export CATALINA_TMPDIR=/tmp
$ sudo /etc/init.d/tomcat6 restart
 * Stopping Tomcat servlet engine tomcat6
   ...done.
 * Starting Tomcat servlet engine tomcat6
   ...done.
$ sudo jstack -l 5934 // new PID after restart
5934: Unable to open socket file: target process not responding or HotSpot VM not loaded
The -F option can be used when the target process is not responding

更新:

我也尝试过 sudo -u tomcat6 jstack -l -F 5730 > threaddumpexceptions2.txt 但它只在控制台上给了我大量的异常。

I am running Ubuntu server edition and I wanted to take a thread dump of Tomcat.

So, I first tried to find out which PID tomcat uses:

$ jps -l
5809 sun.tools.jps.Jps

But it's not there?

So, I used top instead and found out the PID 5730.

Then I called jstack to get the thread dump:

$ sudo jstack -l 5730
5730: Unable to open socket file: target process not responding or HotSpot VM not loaded
The -F option can be used when the target process is not responding

What's going on? :-(

I already tried to export CATALINA_TMPDIR as described in Jstack and Jstat stopped working with upgrade to JDK6u23 but that didn't change anything:

$ export CATALINA_TMPDIR=/tmp
$ sudo /etc/init.d/tomcat6 restart
 * Stopping Tomcat servlet engine tomcat6
   ...done.
 * Starting Tomcat servlet engine tomcat6
   ...done.
$ sudo jstack -l 5934 // new PID after restart
5934: Unable to open socket file: target process not responding or HotSpot VM not loaded
The -F option can be used when the target process is not responding

Update:

I also tried sudo -u tomcat6 jstack -l -F 5730 > threaddumpexceptions2.txt but it only gives me tons of exceptions on the console.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

乄_柒ぐ汐 2024-12-11 08:36:54

我通过做两件事来让它工作:

  1. 更改调用:sudo -u tomcat6 jstack -J-d64 -m pid
  2. 用 Sun 原始的 sun-6-jdk 和 sun-6-jre 包替换 OpenJDK

< strong>第 1 部分的说明:我切换到 64 位模式,使用 sudo 并以 Tomcat 用户身份运行命令。

注意:第 2 部分可能不是必需的。对于某些用户来说,第 1 部分似乎就足够了。事实上,首先尝试仅添加 sudo 命令。它可能已经成功了。

I got it working by doing two things:

  1. Changed call to: sudo -u tomcat6 jstack -J-d64 -m pid
  2. Replaced OpenJDK with Sun's original sun-6-jdk and sun-6-jre packages

Explanation for part 1: I switched to 64-bit mode, used sudo and run the command as Tomcat user.

Note: Part 2 might not be necessary. For some users it seems like part 1 is enough. In fact, try to add just the sudo command first. It might already do the trick.

演出会有结束 2024-12-11 08:36:54

我认为您需要以运行 Tomcat 进程的同一用户身份运行 jstack。另请注意,jps 仅返回当前用户的进程。您可以通过使用 sudo 运行 jps 或作为 Tomcat 进程用户来获取 Tomcat 进程的 pid。

此错误报告也可能有用:https://bugs.launchpad .net/ubuntu/+source/sun-java6/+bug/597098

I think you need to run jstack as the same user that runs the Tomcat process. Note also that jps only returns processes for the current user. You would get the pid for the Tomcat process by running jps with sudo or as the Tomcat process user.

This bug report may also be useful: https://bugs.launchpad.net/ubuntu/+source/sun-java6/+bug/597098

归属感 2024-12-11 08:36:54

@Valmar,我在这里找到了相同主题的帖子。
无法获取线程转储?有什么想法为什么我的应用程序会阻塞吗?

似乎解决方法是sudo -u tomcat6 Kill -3

@Valmar, I find the same topic post here.
Unable to get thread dump? Any ideas why my app blocks?

It seems the workaround is sudo -u tomcat6 kill -3 <pid>.

捎一片雪花 2024-12-11 08:36:54

尝试切换到进程用户然后使用jstack:

sudo -u {进程用户} jstack >倾倒

Try to switch to process user and then use jstack:

sudo -u {process user} jstack > dump

肤浅与狂妄 2024-12-11 08:36:54

这也对我有用:

sudo -u tomcat6 Kill -3 pid

看起来好像什么也没发生,但是当您查看日志时,堆栈就在那里。如果你没有预料到它们,它们看起来就像是例外。

This also worked for me:

sudo -u tomcat6 kill -3 pid

It looks like nothing happens but when you look in the logs the stacks are there. They look like exceptions if your not expecting them.

与他有关 2024-12-11 08:36:54

我发现使用“ps -eo pid,user,command |”之类的东西很有用。 grep java' 查找实际使用的 java 命令,然后使用该目录查找匹配的 jstack 等。

# ps -eo user,command | grep '[j]ava' | cut -d' ' -f1
someuser /usr/lib/jvm/java/bin/java

# /usr/lib/jvm/java/bin/java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)

因此它是 64 位,以“someuser”身份运行。 su 到该用户并从同一目录运行 run jstack 等。 (即 /usr/lib/jvm/java/bin/jstack

当您在具有各种不同 Java 安装/实现的服务器上时很有用。

I find it useful to use something like 'ps -eo pid,user,command | grep java' to find the actual java command being used, then use the directory to find the matching jstack etc.

# ps -eo user,command | grep '[j]ava' | cut -d' ' -f1
someuser /usr/lib/jvm/java/bin/java

# /usr/lib/jvm/java/bin/java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)

So its 64-bit, running as 'someuser'. su to that user and run run jstack etc. from that same directory. (ie. /usr/lib/jvm/java/bin/jstack

Useful when you're on a server with various different installations / implementations of Java.

计㈡愣 2024-12-11 08:36:54

对于遇到此问题的 Tomcat 用户,请检查您的 catalina.out 日志文件。

我遇到了同样的问题“22693:无法打开套接字文件:目标进程没有响应或 HotSpot VM 未加载”。我放弃了,并试图找到有关锁定之前发生的事情的任何信息,但日志文件中出现了 jstack 输出。

For Tomcat users having this issue, check your catalina.out log file.

I was having the same problems "22693: Unable to open socket file: target process not responding or HotSpot VM not loaded". I gave up and was trying to find anything about what happened before it locked up, but then there was the jstack output in the log file.

阿楠 2024-12-11 08:36:54

我遇到了同样的问题,但以下解决方案没有对我有用:

jstack <pid>
jstack -J-d64 -m <pid>
sudo -u <user> jstack ...

我最终将 JDK 从jdk1.6.0_24升级到jdk1.7.0_67并且每件事都有效。

I had same problem, but none of below solution worked for me:

jstack <pid>
jstack -J-d64 -m <pid>
sudo -u <user> jstack ...

I finally upgraded JDK from jdk1.6.0_24 to jdk1.7.0_67 and every things worked.

世俗缘 2024-12-11 08:36:54

对于那些在被问到这个问题六年后找到答案并且使用 CentOS 7 的人来说,请注意,SELinux 将阻止 jmap 写入堆转储,因为开箱即用,它将拒绝写入套接字,除非该目录的类型为 tomcat_tmp_t

就我而言,我将堆转储写入 /usr/share/tomcat/.jmap 下。该目录由我的运行时用户拥有。

因此,允许 jmap 写入此目录:

semanage fcontext -a -t tomcat_tmp_t "/usr/share/tomcat/.jmap(/.*)?"
restorecon /usr/share/tomcat -vR

这允许我们以 tomcat 用户身份运行:

jmap -dump:format=b,file=/usr/share/tomcat/.jmap/tomcat-`date +%s`.bin <pid>

For those finding this answer six years after it was asked and they are on CentOS 7 note that SELinux will stop jmap from writing the heap dumps as, out of the box, it will deny writing to a socket unless the directory has the type tomcat_tmp_t.

In my case, I write my heap dumps under /usr/share/tomcat/.jmap. This directory is owned by my runtime user.

Therefore to allow jmap to write to this directory:

semanage fcontext -a -t tomcat_tmp_t "/usr/share/tomcat/.jmap(/.*)?"
restorecon /usr/share/tomcat -vR

Which allows us to then run, as our tomcat user:

jmap -dump:format=b,file=/usr/share/tomcat/.jmap/tomcat-`date +%s`.bin <pid>
一身仙ぐ女味 2024-12-11 08:36:54

我的问题是,我通过终端运行了该过程。然后为了测试它的 jstack,我通过 ctrl+z 暂停了该过程。该进程无法响应。为了解决这个问题,我通过fg恢复了该进程,并通过另一个终端检查了它的jstack。

My problem was, I ran the process by the terminal. Then for testing Its jstack, I paused the process by ctrl+z. The process was not able to respond. To solve this problem, I resumed the process by fg and checked its jstack by another terminal.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文