How to send interrupt key sequence to a Java Proce

2019-03-15 19:38发布

I've got a handle to a Java Process instance and its associated streams. It's a console program. I'd like to simulate a break sequence. On Windows this is Ctrl-C. Is this possible without natives?

The reason for doing this: the console program is a command-line console itself, controlling a virtual machine for another language. The user can run another program from this console program. While a program is running, the break sequence will interrupt execution of the underlying program and cause the console program to go into debug mode.

We are Java-wrapping this console debugger so that it can be driven via an IDE (Eclipse). Sending the break sequence will be the equivalent of pressing "suspend" in the Eclipse debugger.

1条回答
Animai°情兽
2楼-- · 2019-03-15 20:25

You probably want to look into SendSignal. This will send a ctrl-Break to a Java Process. I assume your goal is to cause a stack dump, which a CTRL-C (signal 3 aka SIGQUIT) will do for a running Java process?

查看更多
登录 后发表回答