在Android的处理UNIX信号 [英] Handling unix signals in Android

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

问题描述

我写会谈到使用命名管道C ++应用程序的Java应用程序。当C ++应用程序死亡时,Java得到SIGPIPE和Java应用程序死亡。

I am writing a Java application that talks to a C++ application using named pipes. When the C++ application dies, the Java gets SIGPIPE and the Java application dies.

在C / C ++我知道如何捕获该信号并忽略它。是否有可能做在Android / Java的?

On C/C++ I know how to catch that signal and ignore it. Is it possible to do something similar on Android/Java?

推荐答案

看来这是不是真的有可能。可用的最好的解决办法是添加一个关闭挂钩和优雅重新启动应用程序,如下所述:

It seems this is not really possible. The best solution available would be to add a shut down hook and "gracefully" restart the application, as described here:

编辑:

我需要这个,因为(当时)我有JNI code上,我开了一个FD和R / W到它。在FD被打开了一个名为socket(UNIX管道),而当管的远程端(对我来说一个守护进程,或Android C /服务)关闭连接(或死亡),你的身边会得到一个信号。这并不总是好的。恕我直言,最好的处理这应该利用好老的纯C code处的信号处理程序,只吞下它(否则 - 你应该通知您的应用程序的Java端)。

I needed this because (back then) I had JNI code on which I opened a FD and r/w to it. The FD was opened to a named socket (a Unix pipe), and when the remote side of the pipe (in my case a daemon, or Android C/service) closes the connection (or dies), your side will get a signal. This is not always nice. IMHO the best to handle this should be using a signal handler from good old plain-C code, and just swallow it (otherwise - you should notify the Java side of your app).

这篇关于在Android的处理UNIX信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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