从JVM发送POSIX信号 [英] Sending a POSIX signal from the JVM

查看:128
本文介绍了从JVM发送POSIX信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从JVM中发送POSIX信号? (在Java或Clojure中)

How do I send a POSIX signal from within the JVM? (in Java or Clojure)

我从未想过这会成为一个问题,直到我尝试谷歌搜索 - 有很多关于处理信号的信息,但没有关于发送它们。

I never thought this would be an issue until I tried googling it — there is lots of information about handling signals, but nothing about sending them.

如果不使用JNI或调用shell执行kill,还有其他方法可以向PID发送信号吗?

Short of using the JNI or calling the shell to execute "kill", is there any other way to send a signal to a PID?

推荐答案

好的。回答我自己:我查看了建议的库,但我很担心在很多代码上引入新的依赖项,特别是如果我只使用它的一小部分。

Ok. Answering myself: I looked at the suggested libraries, but I am wary of introducing new dependencies on lots of code, especially if I'll only use a small part of it.

事实证明,最简单的方法是使用JNA并与系统(libc)API接口。在clojure中,这几乎相当于:

It turns out the easiest way is to use JNA and interface with the system (libc) API. In clojure this pretty much amounts to:

(jna-invoke整数杀死pid signo)

(jna-invoke Integer kill pid signo)

(:使用net.n01se.clojure-jna)当然。

after doing a (:use net.n01se.clojure-jna) of course.

由于这个软件不打算在Windows上运行,我对这个解决方案应该没用适用于所有POSIX系统(MacOS和Linux是我感兴趣的)。

Since this software is not intended to ever run on Windows, I'm fine with this solution which should work on all POSIX systems (MacOS and Linux are what I'm interested in).

这篇关于从JVM发送POSIX信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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