11

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.

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.

ShabbyDoo
  • 1,256
  • 1
  • 11
  • 20

2 Answers2

17

Ctrl-\ is the UNIX/Linux equivalent of Windows Ctrl-Break. Wikipedia also 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)).

Tom Hawtin - tackline
  • 145,806
  • 30
  • 211
  • 305
  • 1
    Yes, usually the terminal is bound for C-\ to send SIGQUIT. This is configurable with `stty quit`, and I'm not sure if it's the default on all systems. – ephemient May 11 '09 at 22:39
  • @ephemient it's not always, but even exotic terminals tend to use that. My IBM 3161 does, for example. http://i.imgur.com/6DejIxY.jpg – Wyatt Ward Jan 13 '16 at 18:08
  • 1
    A [similar topic](https://unix.stackexchange.com/questions/45646/how-do-i-exit-or-cancel-a-bad-bash-command) has been opened and it helped me a lot, for example "Ctrl+Z". – NCC1701 Jun 08 '21 at 17:13
  • According to https://www.gnu.org/software/libc/manual/html_node/Termination-Signals.html, SIGQUIT produces a core dump, so I think Ctrl-Break would be more like a SIGTERM, i.e. `kill -TERM` in Linux. – paulie4 Jun 17 '21 at 17:02
10

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).

bm212
  • 1,429
  • 11
  • 12
  • I don't have a linux box with a jvm that supports the -XX:+HeapDumpOnCtrlBreak option so can't test this (and I've never actually done it so can't vouch that it works). – bm212 May 11 '09 at 22:10
  • I'd much rather see a suggestion of "kill -QUIT" than "kill -3", even though they're equivalent. – ephemient May 11 '09 at 22:40
  • According to https://www.gnu.org/software/libc/manual/html_node/Termination-Signals.html, SIGQUIT produces a core dump, so I think Ctrl-Break would be more like a SIGTERM, i.e. `kill -TERM` in Linux. – paulie4 Jun 17 '21 at 17:02