Handling unix signals in Android

痴心易碎 提交于 2019-12-10 13:26:05

问题


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.

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


回答1:


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:

EDIT:

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

http://stackoverflow.com/questions/2541597/how-to-gracefully-handle-the-sigkill-signal-in-java

来源:https://stackoverflow.com/questions/10224088/handling-unix-signals-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!