java 如何将 Ctrl-Break 发送到正在运行的 Linux 进程?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/850163/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 14:03:23  来源:igfitidea点击:

How can one send a Ctrl-Break to a running Linux process?

javalinuxkilljvm-arguments

提问by ShabbyDoo

I am debugging a memory leak in an application running on Sun's JDK 1.4.2_18. It appears that this version supports the command line param -XX:+HeapDumpOnCtrlBreak which supposedly causes the JVM to dump heap when it encounters a control-break. How does one send this to a background process on a Linux box? It appears that kill signals are the way this ought to work, but I kill -l doesn't report anything that is obviously a Ctrl-Break, at least on my Ubuntu box.

我正在调试在 Sun 的 JDK 1.4.2_18 上运行的应用程序中的内存泄漏。似乎这个版本支持命令行参数 -XX:+HeapDumpOnCtrlBreak,这可能会导致 JVM 在遇到控制中断时转储堆。如何将其发送到 Linux 机器上的后台进程?看起来 kill 信号是应该起作用的方式,但是我 kill -l 没有报告任何明显是 Ctrl-Break 的东西,至少在我的 Ubuntu 机器上是这样。

Update: I tested Kill -3 with Sun JDK 1.4.2_18 (_14 was the first to dump heap this way), and it worked. A heap dump file was created, and the process was still running.

更新:我使用 Sun JDK 1.4.2_18 测试了 Kill -3(_14 是第一个以这种方式转储堆的),并且成功了。已创建堆转储文件,并且进程仍在运行。

回答by Tom Hawtin - tackline

Ctrl-\ is the UNIX/Linux equivalent of Windows Ctrl-Break. Wikipediaalso tells me that you can also use Ctrl-4 or SysRq on the Linux virtual console (I guess you'd need something weird for a normal terminal emulator to pass representations of those key presses (over ssh/telnet)).

Ctrl-\ 是 UNIX/Linux 等价于 Windows Ctrl-Break。维基百科还告诉我,你也可以在 Linux 虚拟控制台上使用 Ctrl-4 或 SysRq(我猜你需要一些奇怪的东西来让普通终端模拟器传递这些按键的表示(通过 ssh/telnet))。

回答by bm212

kill -QUIT might do it (it will generate a thread dump which is generated by ctrl-break on windows. I haven't tried it with the heap dump option though).

kill -QUIT 可能会这样做(它会生成一个线程转储,该转储由 Windows 上的 ctrl-break 生成。不过我还没有尝试使用堆转储选项)。