如何从Java向外部进程发送SIGINT信号? [英] How to send SIGINT signal from Java to an external process?

查看:391
本文介绍了如何从Java向外部进程发送SIGINT信号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java应用程序,它创建一个外部进程并通过InputStream读取进程'stdout。当我完成它时,我需要能够杀死进程。有没有办法向这个过程发送SIGINT信号? (好像我从控制台按了Ctrl + C)。

I have a Java app that creates an external process and reads the process' stdout through an InputStream. I need to be able to kill the process when I am done with it. Is there a way to send a SIGINT signal to this process? (as if I pressed Ctrl+C from the console).

外部进程不是我的代码,我无法修改它。

The external process is not my code and I cannot modify it.

推荐答案

您是否正在以 java.lang.Process 运行外部程序?由于Process类具有 destroy()方法。

Are you running the external program as a java.lang.Process? As the Process class has a destroy() method.

这篇关于如何从Java向外部进程发送SIGINT信号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆