[LINUX] Detect and process signals in Java.

Conclusion

It is better not to.

What is a "signal" in the first place?

Signal (English: signal) is a form of limited interprocess communication in POSIX-compliant OS such as UNIX and Unix. A mechanism for transmitting the occurrence of asynchronous events between processes or threads.

For example, you can stop it with Ctrl + C while the program is running, At this time, SIGINT is sent to the OS, a kill command is issued, and it is stopped.

To detect signals in Java

There is an API called sun.misc. {Signal, SignalHandler}. However, this API is not supported, and it is uncertain whether it will remain or disappear in Java 9. https://blogs.oracle.com/java/get-ready-jdk9 scared. very scary.

For the time being, I will use this in this summary.

First, let's find out which signals should not be used.

There are signals that the VM is grasping, so I would like to avoid that. That's why.

Signals used by the JVM

http://www.ibm.com/support/knowledgecenter/ja/SSYKE2_7.0.0/com.ibm.java.zos.71.doc/user/sighand.html As written here, the main signals are quite used.

Signals used by HotSpot VM

http://www.oracle.com/technetwork/java/javase/signals-139944.html Again, the main signal is quite used. (It feels like the JVM)

What you can see so far

--It is safer not to detect the main signal (SIGINT or SIGTERM) --User definition (SIGUSR1 / SIGUSR2) is also used

Then use SIGRTMIN or later! !! !!

I can't say that. (But)

http://d.hatena.ne.jp/Kazuhira/20150422/1429713440 As written here, it cannot be used after RTMIN. sad. Very sad.

That's why

After spending a whole day so far, I decided to take another method. Fortunately, it wasn't a requirement to "detect the signal", so it's quite likely to be another way. Please be careful if there is a ** requirement to "detect a signal" **.


** But it's good because I learned !!! **
that's all.

Recommended Posts

Detect and process signals in Java.
Overlapping regular expressions in Python and Java
Differences in syntax between Python and Java
I wrote a class in Python3 and Java
Facade pattern in Java
Singleton pattern in Java
Flyweight pattern in Java
Handle signals in C
Observer pattern in Java
Linux permissions in Java
Use DataFrame in Java
Iterator pattern in Java
Decorator pattern in Java
Prototype pattern in Java
Proxy pattern in Java
Poisson distribution and Poisson cumulative distribution plot via sqlite in Python and Java
I tried programming the chi-square test in Python and Java.
Remove leading and trailing whitespace in Python, JavaScript, or Java
Coordination of each process in MPI and buffering of standard output
Graph the Poisson distribution and the Poisson cumulative distribution in Python and Java, respectively.
Difference between process and job
Clipping and normalization in TensorFlow
I compared Java and Python!
Stack and Queue in Python
Template Method pattern in Java
Unittest and CI in Python
Detect keystrokes in python (tty)
Implement Gaussian process in Pyro
Solving in Ruby, Python and Java AtCoder ABC141 D Priority Queuing
I tried using docomo speech recognition API and Google Speech API in Java
How to display bytes in the same way in Java and Python