Documentation Contents

Signal Chaining

The Java 2 SDK, Standard Edition, (JDK) v1.4 contains a new signal-chaining facility. Signal-chaining enables the Java Platform to better interoperate with native code that installs its own signal handlers. The facility works on both Solaris and Linux platforms.

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.

The signal-chaining facility offers the following:

Pre-installed signal handlers (A) are supported by means of saving existing signal handlers, for signals that are used by the VM, when the VM is first created. Later, when any of these signals are raised and found not to be targeted at the Java HotSpot VM, the pre-installed handlers are invoked. In other words, pre-installed handlers are "chained" behind the VM handlers for these signals.

The signal-chaining facility also allows an application to link and load a shared library libjsig.so before libc/libthread/libpthread. This library ensures that calls such as signal(), sigset(), and sigaction() are intercepted so that they do not actually replace the Java HotSpot VM's signal handlers if the handlers conflict with those already installed by the Java HotSpot VM (B). Instead, these calls save the new signal handlers, or "chain" them behind the VM-installed handlers. Later, when any of these signals are raised and found not to be targeted at the Java HotSpot VM, the pre-installed handlers are invoked. libjsig.so is not needed if (B) is not required.

To use libjsig.so, either link it with the application that creates/embeds a HotSpot VM, for example:

cc -L <libjvm.so dir> -ljsig -ljvm java_application.c
or use LD_PRELOAD environment variable, for example:
export LD_PRELOAD=<libjvm.so dir>/libjsig.so; java_application (ksh)

setenv LD_PRELOAD <libjvm.so dir>/libjsig.so; java_application (csh)
The interposed signal()/sigset()/sigaction() return the saved signal handlers, not the signal handlers installed by the Java HotSpot VM which are seen by the OS.

The signal-chaining facility was introduced to address Request for Enhancement number 4381843.


Oracle and/or its affiliates Copyright © 1993, 2018, Oracle and/or its affiliates. All rights reserved.
Contact Us