java.lang.Object | |
↳ | sun.misc.Signal |
This class provides ANSI/ISO C signal support. A Java program can register signal handlers for the current process. There are two restrictions:
Signal.handle
function raises an IllegalArgumentException
if such an attempt
is made.
Signal.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 priority Thread.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:
constructs a signal object corresponding tonew Signal("INT");
SIGINT
, which is
typically produced when the user presses Ctrl-C
at the command line.
The Signal
constructor throws IllegalArgumentException
when it is passed an unknown signal.
This is an example of how Java code handles SIGINT
:
SignalHandler handler = new SignalHandler () { public void handle(Signal sig) { ... // handle SIGINT } }; Signal.handle(new Signal("INT"), handler);
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a signal from its name.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Compares the equality of two
Signal objects. | |||||||||||
Returns the signal name.
| |||||||||||
Registers a signal handler.
| |||||||||||
Returns a hashcode for this Signal.
| |||||||||||
Raises a signal in the current process.
| |||||||||||
Returns a string representation of this signal.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Constructs a signal from its name.
name | the name of the signal. |
---|
IllegalArgumentException | unknown signal |
---|
Compares the equality of two Signal
objects.
other | the object to compare with. |
---|
Signal
objects are equal.
Registers a signal handler.
sig | a signal |
---|---|
handler | the handler to be registered with the given signal. |
IllegalArgumentException | the signal is in use by the VM |
---|
Returns a hashcode for this Signal.
Raises a signal in the current process.
sig | a signal |
---|
IllegalArgumentException |
---|
Returns a string representation of this signal. For example, "SIGINT"
for an object constructed using new Signal ("INT")
.