Module jdk.unsupported
Package sun.misc

Class Signal



  • public final classSignalextendsObject
    This class provides ANSI/ISO C signal support. A Java program can register signal handlers for the current process. There are two restrictions:
    • Java code cannot register a handler for signals that are already used by the Java VM implementation. TheSignal.handle function raises anIllegalArgumentException if such an attempt is made.
    • WhenSignal.handle is called, the VM internally registers a special C signal handler. There is no way to force the Java signal handler to run synchronously before the C signal handler returns. Instead, when the VM receives a signal, the special C signal handler creates a new thread (at priorityThread.MAX_PRIORITY) to run the registered Java signal handler. The C signal handler immediately returns. Note that because the Java signal handler runs in a newly created thread, it may not actually be executed until some time after the C signal handler returns.

    Signal objects are created based on their names. For example:

     new Signal("INT");
    constructs a signal object corresponding toSIGINT, which is typically produced when the user pressesCtrl-C at the command line. TheSignal constructor throwsIllegalArgumentException when it is passed an unknown signal.

    This is an example of how Java code handlesSIGINT:

     SignalHandler handler = new SignalHandler () {     public void handle(Signal sig) {       ... // handle SIGINT     } }; Signal.handle(new Signal("INT"), handler);
    Since:
    1.2
    See Also:
    SignalHandler