posix
Class Signal

java.lang.Object
  extended by posix.Signal

public class Signal
extends Object

A posix signal. A posix signal represents an external event of some sort. For instance, SIGINTR means that a user interrupt signal was raised by the tty driver - usually because the user pressed the INTR key (typically ^C).

Some posix signals represent internal software errors. For example SIGBUS means that a load or store was attempted with incorrect alignment. We do not handle these internal events for Java - only the JVM could do something sensible with them. Furthermore, some posix signals are probably used by the JVM itself. For example, SIGCHLD means that a process started via Runtime.exec() has terminated. For this reason, only selected signals are exported via static constants.

Each Signal is in one of three states. SIG_DFL means that the default action is taken when the signal is received. This usually means stopping the JVM process. Whether any cleanup takes place depends on the JVM. SIG_IGN means that the signal is ignored. SIG_EVT means that the signal is converted to a JDK1.1 style Java event.

WARNING

The Signal class will not crash. However, whether or not a given signal can actually be trapped is highly dependent on both OS and JVM implementation. When multiple threads listen to the same signal, posix does not specify which thread gets the signal. So do not rely on a signal being trapped on all platforms. This may be rectified in the future if JNI provides some kind of signal interface, or posix provides some way of reliably distributing signals to multiple threads.


Field Summary
static int SIG_DFL
           
static int SIG_EVT
           
static int SIG_IGN
           
static Signal SIGDANGER
          Paging space is low, or power failure.
static Signal SIGHUP
          The terminal or X session has disconnected.
static Signal SIGINT
          The user has sent an interrupt.
static Signal SIGQUIT
          The user has sent a diagnostic abort.
static Signal SIGTERM
          The process is being terminated.
static Signal SIGUSR1
          Application dependent signal.
static Signal SIGUSR2
          Application dependent signal.
static Signal SIGWINCH
          The terminal window has changed size.
 
Method Summary
 void addSignalListener(SignalListener l)
           
 int getAction()
           
 void kill(int pid)
          Send this Signal to another process.
static int kill(int pid, int sig)
          Send signal to process using posix call.
 void processSignal()
          Send a SignalEvent to all listeners.
 void removeSignalListener(SignalListener l)
           
 void setAction(int action)
          Set the signal handling action type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SIGHUP

public static final Signal SIGHUP
The terminal or X session has disconnected.


SIGINT

public static final Signal SIGINT
The user has sent an interrupt.


SIGQUIT

public static final Signal SIGQUIT
The user has sent a diagnostic abort.


SIGUSR1

public static final Signal SIGUSR1
Application dependent signal.


SIGUSR2

public static final Signal SIGUSR2
Application dependent signal.


SIGDANGER

public static final Signal SIGDANGER
Paging space is low, or power failure.


SIGTERM

public static final Signal SIGTERM
The process is being terminated.


SIGWINCH

public static final Signal SIGWINCH
The terminal window has changed size.


SIG_DFL

public static final int SIG_DFL
See Also:
Constant Field Values

SIG_IGN

public static final int SIG_IGN
See Also:
Constant Field Values

SIG_EVT

public static final int SIG_EVT
See Also:
Constant Field Values
Method Detail

setAction

public void setAction(int action)
Set the signal handling action type.

Parameters:
action - one of SIG_DFL,SIG_IGN,SIG_EVT
Throws:
IllegalStateException - if the JVM already traps this signal

getAction

public final int getAction()

addSignalListener

public void addSignalListener(SignalListener l)

removeSignalListener

public void removeSignalListener(SignalListener l)

processSignal

public void processSignal()
Send a SignalEvent to all listeners.


kill

public static int kill(int pid,
                       int sig)
Send signal to process using posix call.

Parameters:
pid - process id to signal
sig - native signal index
Returns:
0 on success or errno

kill

public void kill(int pid)
          throws IPCException
Send this Signal to another process.

Parameters:
pid - the Posix process id
Throws:
IPCException