Reputation: 11
I need to create a JNI c library for patient monitor subsystem under Linux platform. I have to read the data and write the command through USB Serial port. Whenever the port is open, the device sends multiple types of data continuously with different frequencies and sizes.
From Java, I am running a separate thread which calls the native jni c code, there I am calling a C-function to read data from serial port in while(1) loop based on RX_Flag which was enabled inside the signal handler. The signal handler function is connected with SIGIO using sigaction during port configuration. My expectation is, whenever the data arrives in the port, triggers the signal, that signal is connected to the signalIO handler, enables the RX_Flag.
Based on flag_values, reads, parses and sends back the array to Java. I am calling the receive function using pthread from main in C, it was working fine. But from Java, I was stuck in the first step itself. Am not receiving the IO Signals properly, after sometime IO Signals not arrived. In Native C, whenever the IO signal arrives, it enables the flag in a separate processes. For that, is there any additional things I have to add inside the Signal IOhandler?
Am I going in a correct way or is there an alternate way to implement this?
Upvotes: 1
Views: 157
Reputation: 9422
JVM uses signals for its own purposes, this is summarized in this thread Cannot catch SIGINT signal in a producer-consumer program where JNI is used in consumer thread. There was introduced a technique called signal chaining by java to handle this ...
The signal-chaining facility was introduced to remedy a problem with signal handling in previous versions of the Java HotSpot VM. Prior to version 1.4, the Java HotSpot VM would not allow application-installed signal handlers for certain signals including, for example, SIGBUS, SIGSEGV, SIGILL, etc, since those signal handlers could conflict with the signal handlers used internally by the Java HotSpot VM
source : https://docs.oracle.com/javase/8/docs/technotes/guides/vm/signal-chaining.html
If an application with native code requires its own signal handlers, then it might need to be used with the signal chaining facility
source : https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/signals003.html
SIGIO
is used by current JVM : https://github.com/JetBrains/jdk8u_hotspot/blob/master/src/os/linux/vm/jvm_linux.cpp
to verify that SIGIO is triggered you can use strace
or auditd
( https://www.ibm.com/developerworks/community/blogs/aimsupport/entry/Finding_the_source_of_signals_on_Linux_with_strace_auditd_or_Systemtap?lang=en )
Upvotes: 1