Up: Classes   [Index]


SignalHandler

SignalHandler Class

Class SignalHandler provides the methods that install handlers for signals from the operating system.

Applications can also define signal handlers with this class. Signal handler methods need to use the calling conventions of C functions. See Method functions.

For POSIX signals, you can use a method to set the signal number.

Signal    Method       Signal
------    ------       ------
SIGHUP    setSigHup    Termination of terminal process.
SIGINT    setSigInt    Interrupt from keyboard.
SIGQUIT   setSigQuit   Quit from keyboard.
SIGILL    setSigIll    Illegal instruction.
SIGABRT   setSigAbrt   Abort from C library abort(3).
SIGFPE    setSigFpe    Floating point exception.
SIGKILL   -            Kill process - non-catchable.
SIGSEGV   setSigSegv   Invalid memory address.
SIGPIPE   setSigPipe   Broken pipe or write to pipe with no reader.
SIGALRM   setSigAlrm   Timer signal from C library alarm(2).
SIGTERM   setSigTerm   Process termination.
SIGUSR1   setSigUsr1   User defined.
SIGUSR2   setSigUsr2   User defined.
SIGCHLD   setSigChld   Child process stopped or terminated.
SIGCONT   setSigCont   Continue stopped process.
SIGSTOP   -            Stop process - non-catchable.
SIGTSTP   setSigTstp   Stop from tty.
SIGTTIN   setSigTtin   Terminal input for background process.
SIGTTOU   setSigTtou   Terminal output from background process.

You can also set system-specific signals by number with setSigNo.

SignalHandler methods can also send SignalEvent objects to Ctalk programs. Refer to Method functions, SignalEvent, and __ctalkNewSignalEventInternal.

Internally, methods in SignalHandler class use the library functions __ctalkIgnoreSignal (), __ctalkDefaultSignalHandler (), __ctalkInstallHandler (), and __ctalkSystemSignalNumber. Signal handlers need to be reset after each usage. Refer to the timeclient.c example program.

Instance Variables

attributes

The value of attributes can be one of the following.

SIG_DEFAULT

The application uses the operating system’s default signal handler for the signal. The operating system’s documentation describes how it handles signals.

SIG_IGNORE

The application ignores the signal.

SIG_METHOD

The application provides a method to handle the signal.

handler

The value is an instance method of class SignalHandler that is provided by the application.

Instance Methods

defaultHandler (void)

Install the operating system’s default handler for the receiver’s signal number sigNo. The operating system’s documentation describes how it handles signals.

ignoreSignal (void)

Set the receiver signal handler to ignore a signal.

installHandler (OBJECT *(*method)(int))

Install method as the receiver’s signal handler. The method must be callable as a C function. See Method functions.

new (char *name)

Create new SignalHandler objects with the name(s) given in the argument list.

raiseSignal (void)

Send the signal of the receiver’s sigNo variable to the current program.

setSigAbrt (void)

Set the signal of the receiver’s handler to SIGABRT.

setSigAlrm (void)

Set the signal of the receiver’s handler to SIGALRM.

setSigChld (void)

Set the signal of the receiver’s handler to SIGCHLD.

setSigCont (void)

Set the signal of the receiver’s handler to SIGCONT.

setSigFpe (void)

Set the signal of the receiver’s handler to SIGFPE.

setSigHup (void)

Set the signal of the receiver’s handler to SIGHUP.

setSigIll (void)

Set the signal of the receiver’s handler to SIGILL.

setSigInt (void)

Set the signal of the receiver’s handler to SIGINT.

setSigNo (int signum)

Set the signal number of the receiver to signum.

setSigPipe (void)

Set the signal of the receiver’s handler to SIGPIPE.

setSigQuit (void)

Set the signal of the receiver’s handler to SIGQUIT.

setSigSegv (void)

Set the signal of the receiver’s handler to SIGSEGV.

setSigTerm (void)

Set the signal of the receiver’s handler to SIGTERM.

setSigTstp (void)

Set the signal of the receiver’s handler to SIGTSTP.

setSigTtin (void)

Set the signal of the receiver’s handler to SIGTTIN.

setSigTtou (void)

Set the signal of the receiver’s handler to SIGTTOU.

setSigUsr1 (void)

Set the signal of the receiver’s handler to SIGUSR1.

setSigUsr2 (void)

Set the signal of the receiver’s handler to SIGUSR2.

signalProcessID (int processid)

Send the signal sigNo of the receiver to process processid.

sigName (Integer signal_number)

Return a String with the name of the signal whose number is given as the argument.

sigNum (String signal_name)

Return an Integer with the value of the signal whose name is given as the argument.

waitStatus (Integer child_pid, Integerchild_return_val, Integer child_signal, Integer errno)

Checks for a change in the status of the child process given by child_pid.

The return value is an Integer with the value 0, which indicates that the child process has not changed status, an Integer equal to child_pid, or -1.

If the return value is equal to child_pid, then the processes’ return code is returned in child_return_val if the process exited normally. If the child process was terminated by an uncaught signal, the signal’s number is returned in child_signal.

If the return value is -1, the system errno is returned in errno, which indicates an error when the parent process called waitStatus.

Here is an example.


SignalHandler new s;
Integer new r, childProcessID, child_retval, child_sig,
        child_errno;

 ... do stuff ...

 r = s waitStatus childProcessID,
	child_retval, child_sig, child_errno;

 if (r == childProcessID) {
    if (child_sig) {
       printf ("Child received signal %s - exiting.\n",
		  s sigName child_sig);
	  exit (1);
    }
 }

 ... do more stuff ...

 exit (0);
 

Up: Classes   [Index]