4.2 Signal Handling

A signal is a form of software interrupt to the normal execution of a user process. Signals occur as a result of a variety of events, including any of the following:

4.2.1 OpenVMS Versus UNIX Terminology

Both OpenVMS and UNIX systems provide signal-handling mechanisms that behave differently but use similar terminology. With the DEC C RTL, you can program using either signal-handling mechanism. Before describing the signal-handling routines, some terminology must be established.

The UNIX term for a software interrupt is signal. A routine called by the UNIX system to process a signal is termed a signal handler.

A software interrupt on an OpenVMS system is referred to as a signal, condition, or exception. A routine called by the OpenVMS system to process software interrupts is termed a signal handler, condition handler, or exception handler.

To prevent confusion, the terms signal and signal handler in this manual refer to UNIX interrupts and interrupt processing routines, while the terms exception and exception handler refer to OpenVMS interrupts and interrupt processing routines.

4.2.2 UNIX Signals and the DEC C RTL

Signals are represented by mnemonics defined in the <signal.h> header file. Table 4-3 lists the supported signal mnemonics and the corresponding event that causes each signal to be generated on the OpenVMS operating system.

Table 4-3 DEC C RTL Signals

Name  Description  Generated by 
SIGABRT[1]  Abort  abort() 
SIGALRM  Alarm clock  Timer AST, alarm routine 
SIGBUS  Bus error  Access violation or change mode user 
SIGCHLD  Child process stopped  Child process terminated or stopped 
SIGEMT  EMT instruction  Compatibility mode trap or opcode reserved to customer 
SIGFPE  Floating-point exception  Floating-point overflow /underflow 
SIGHUP  Hang up  Data set hang up 
SIGILL[1]  Illegal instruction  Illegal instruction, reserved operand, or reserved address mode 
SIGINT  Interrupt  OpenVMS Ctrl/C interrupt 
SIGIOT[1]  IOT instruction  Opcode reserved to customer 
SIGKILL[2],[3]  Kill  External signal only 
SIGQUIT  Quit  Not implemented. 
SIGPIPE  Broken pipe  Write to a pipe with no readers. 
SIGSEGV  Segment violation  Length violation or change mode user 
SIGSYS  System call error  Bad argument to system call 
SIGTERM  Software terminate  External signal only 
SIGTRAP[1]  Trace trap  TBIT trace trap or breakpoint fault instruction 
SIGUSR1  User-defined signal   Explicit program call to raise the signal 
SIGUSR2  User-defined signal   Explicit program call to raise the signal 

[1] Cannot be reset when caught.

[2] Cannot be caught or ignored.

[3] Cannot be blocked.

By default, when a signal (except for SIGCHLD) occurs, the process is terminated. However, you can choose to have the signal ignored by using one of the following functions:


sigaction
signal
sigvec
ssignal

You can have the signal blocked by using one of the following functions:


sigblock
sigsetmask
sigprocmask
sigsuspend
sigpause

Table 4-3 indicates those signals that cannot be ignored or blocked.

You can also establish a signal handler to catch and process a signal by using one of the following functions:


sigaction
signal
sigvec
ssignal

Unless noted in Table 4-3, each signal can be reset. A signal is reset if the signal handler function calls signal or ssignal to re-establish itself to catch the signal. Example 4-1 shows how to establish a signal handler and reset the signal.

The calling interface to a signal handler is:

void handler (int sigint);

Where sigint is the signal number of the raised signal that caused this handler to be called.

A signal handler installed with sigvec remains installed until it is changed.

A signal handler installed with signal or signal remains installed until the signal is generated.

A signal handler can be installed for more than one signal. Use the sigaction routine with the flag SA_RESETHAND to control this.

4.2.3 Signal-Handling Concepts

A signal is said to be generated for (or sent to) a process when the event that causes the signal first occurs. Examples of such events include detection of hardware faults, timer expiration, and terminal activity, as well as the invocation of kill. In some circumstances, the same event generates signals for multiple processes.

Each process has an action to be taken in response to each signal defined by the system. A signal is said to be delivered to a process when the appropriate action for the process and signal is taken.

During the time between the generation of a signal and its delivery, the signal is said to pending. Ordinarily, this interval cannot be detected by an application. However, a signal can be blocked from delivery to a process:

Each process has a signal mask that defines the set of signals currently blocked from delivery to it. The signal mask for a process is initialized from that of its parent. The sigaction, sigprocmask, and sigsuspend function control the manipulation of the signal mask.

The determination of which action is taken in response to a signal is made at the time the signal is delivered, allowing for any changes since the time of generation. This determination is independent of the means by which the signal was originally generated. If a subsequent occurrence of a pending signal is generated, it is implementation-dependent as to whether the signal is delivered more than once. The DEC C RTL delivers the signal only once. The order in which multiple, simultaneously pending signals are delivered to a process is unspecified.

4.2.4 Signal Actions

This section applies to the sigaction, signal, sigvec, and ssignal functions.

There are three types of action that can be associated with a signal:


SIG_DFL
SIG_IGN
pointer to a function

Initially, all signals are set to SIG_DFL or SIG_IGN prior to entry of the main routine (see the exec functions.) The actions prescribed by these values are:


SIG_DFL - signal-specific default action


SIG_IGN - ignore signal


pointer to a function - catch signal

4.2.5 Signal Handling and OpenVMS Exception Handling

This section discusses how DEC C RTL signal handling is implemented with and interacts with OpenVMS exception handling. Information in this section allows you to write OpenVMS exception handlers that do not conflict with DEC C RTL signal handling. For information on OpenVMS exception handling, see the VAX Procedure Calling and Condition Handling Standard.

The DEC C RTL implements signals with OpenVMS exceptions. When gsignal or raise is called, the signal number is translated to a particular OpenVMS exception, which is used in a call to LIB$SIGNAL. This mechanism is necessary to catch an OpenVMS exception resulting from a user error and translate it into a corresponding UNIX signal. For example, an ACCVIO resulting from a write to a NULL pointer is translated to a SIGBUS or SIGSEGV signal.

Tables 4-4 and 4-5 list the DEC C RTL signal names, the corresponding OpenVMS VAX and OpenVMS Alpha exceptions, the event that generates the signal, and the optional signal code for use with the gsignal and raise functions.

Table 4-4 DEC C RTL Signals and Corresponding OpenVMS VAX Exceptions (VAX only)

Name  OpenVMS Exception  Generated By  Code 
SIGABRT  SS$_OPCCUS  The abort function 
SIGALRM  SS$_ASTFLT  The alarm function  
SIGBUS  SS$_ACCVIO  Access violation 
SIGBUS  SS$_CMODUSER  Change mode user 
SIGCHLD  C$_SIGCHLD  Child process stopped 
SIGEMT  SS$_ COMPAT  Compatibility mode trap 
SIGFPE  SS$_ DECOVF  Decimal overflow trap  FPE_ DECOVF_TRAP 
SIGFPE  SS$_FLTDIV  Floating/decimal division by 0  FPE_FLTDIV_TRAP 
SIGFPE  SS$_FLTDIV_F  Floating divide by 0 fault  FPE_FLTDIV_FAULT 
SIGFPE  SS$_FLTOVF  Floating overflow trap  FPE_FLTOVF_TRAP 
SIGFPE  SS$_FLTOVF_F  Floating overflow fault  FPE_FLTOVF_FAULT 
SIGFPE  SS$_FLTUND  Floating undeflow trap  FPE_FLTUND_TRAP 
SIGFPE  SS$_FLTUND_F  Floating undeflow fault  FPE_FLTUND_FAULT 
SIGFPE  SS$_INTDIV  Integer division by 0  FPE_INTDIV_TRAP 
SIGFPE  SS$_INTOVF  Integer overflow  FPE_INTOVF_TRAP 
SIGFPE  SS$_SUBRNG  Subscript- range  FPE_SUBRNG_TRAP 
SIGHUP  SS$_HANGUP  Data set hangup 
SIGILL  SS$_OPCDEC  Reserved instruction  ILL_PRIVIN_FAULT 
SIGILL  SS$_RADRMOD  Reserved addressing  ILL_RESAD_FAULT 
SIGILL  SS$_ROPRAND  Reserved operand  ILL_ RESOP_FAULT 
SIGINT  SS$_ CONTROLC  OpenVMS Ctrl/C interrupt 
SIGIOT  SS$_ OPCCUS  Customer-reserved opcode  
SIGKILL  SS$_ ABORT  External signal only  -  
SIGQUIT  SS$_ CONTROLY  Ctrl/C if the action for SIGINT is SIG_ DFL 
SIGPIPE  SS$_NOMBX  No mailbox 
SIGSEGV  SS$_ACCVIO  Length violation 
SIGSEGV  SS$_CMODUSER  Change mode user 
SIGSYS  SS$_BADPARAM  Bad argument to system call 
SIGTERM  Not implemented 
SIGTRAP  SS$_TBIT  TBIT trace trap 
SIGTRAP  SS$_BREAK  Breakpoint fault instruction 
SIGUSR1  C$_SIGUSR1  The raise function 
SIGUSR2  C$_SIGUSR2  The raise function 

To call a signal handler that you have established with signal or sigvec, the DEC C RTL intercepts the OpenVMS exceptions that correspond to signals by having an OpenVMS exception handler in the main routine of the program. If your program has a main function, then this exception handler is automatically established. If you do not have a main function, or if your main function is written in a language other than DEC C, then you must invoke the VAXC$CRTL_INIT routine to establish this handler.

The DEC C RTL uses OpenVMS exceptions to implement the setjmp and longjmp functions. When the longjmp function is called, a C$_LONGJMP OpenVMS exception is signaled. To prevent the C$_LONGJMP exception from being interfered with by user exception handlers, use the VAXC$ESTABLISH routine to establish user OpenVMS exception handlers instead of calling LIB$ESTABLISH. The C$_ LONGJMP mnemonic is defined in the <errnodef.h> header file.

If you want to use OpenVMS exception handlers and UNIX signals in your C program, your OpenVMS exception handler must be prepared to accept and resignal the OpenVMS exceptions listed in Tables 4-4 (VAX only) and 4-5 (Alpha only), as well as the C$_LONGJMP exception and any C$ facility exception that might be introduced in future versions of the DEC C RTL. This is because UNIX signals are global in context, whereas OpenVMS exceptions are stack-frame based.

Consequently, an OpenVMS exception handler always receives the exception that corresponds to the UNIX signal before the DEC C RTL exception handler in the main routine does. By resignaling the OpenVMS exception, you allow the DEC C RTL exception handler to receive the exception. You can intercept any of those OpenVMS exceptions yourself, but in doing so you will disable the corresponding UNIX signal.

Table 4-5 DEC C RTL Signals and Corresponding OpenVMS Alpha Exceptions (Alpha only)

Name  OpenVMS Exception  Generated By  Code 
SIGABRT  SS$_OPCCUS  The abort function 
SIGALRM  SS$_ASTFLT  The alarm function  
SIGBUS  SS$_ACCVIO  Access violation 
SIGBUS  SS$_CMODUSER  Change mode user 
SIGCHLD  C$_SIGCHLD  Child process stopped 
SIGEMT  SS$_ COMPAT  Compatibility mode trap 
SIGFP  SS$_ DECDIV  Decimal divide trap  FPE_ DECDIV_TRAP 
SIGFPE  SS$_ DECINV  Decimal invalid operand trap  FPE_DECINV_TRAP 
SIGFPE  SS$_DECOVF  Decimal overflow trap  FPE_DECOVF_TRAP 
SIGFPE  SS$_HPARITH  Floating/decimal division by 0  FPE_FLTDIV_TRAP 
SIGFPE  SS$_HPARITH  Floating overflow trap  FPE_FLTOVF_TRAP 
SIGFPE  SS$_HPARITH  Floating undeflow trap  FPE_FLTUND_TRAP 
SIGFPE  SS$_HPARITH  Integer overflow  FPE_INTOVF_TRAP 
SIGFPE  SS$_HPARITH  Invalid operand  FPE_INVOPR_TRAP 
SIGFPE  SS$_HPARITH  Inexact result  FPE_INXRES_TRAP 
SIGFPE  SS$_INTDIV  Integer div by zero  FPE_INTDIV_TRAP 
SIGFPE  SS$_SUBRNG  Subscript out of range  FPE_SUBRNG_TRAP 
SIGFPE  SS$_SUBRNG1  Subscript1 out of range  FPE_SUBRNG1_TRAP 
SIGFPE  SS$_SUBRNG2  Subscript2 out of range  FPE_SUBRNG2_TRAP 
SIGFPE  SS$_SUBRNG3  Subscript3 out of range  FPE_SUBRNG3_TRAP 
SIGFPE  SS$_SUBRNG4  Subscript4 out of range  FPE_SUBRNG4_TRAP 
SIGFPE  SS$_SUBRNG5  Subscript5 out of range  FPE_SUBRNG5_TRAP 
SIGFPE  SS$_SUBRNG6  Subscript6 out of range  FPE_SUBRNG6_TRAP 
SIGFPE  SS$_SUBRNG7  Subscript7 out of range  FPE_SUBRNG7_TRAP 
SIGHUP  SS$_HANGUP  Data set hangup 
SIGILL  SS$_OPCDEC  Reserved instruction  ILL_PRIVIN_FAULT 
SIGILL  SS$_ROPRAND  Reserved operand  ILL_RESOP_FAULT 
SIGINT  SS$_CONTROLC  OpenVMS Ctrl/C interrupt 
SIGIOT  SS$_OPCCUS  Customer- reserved opcode  
SIGKILL  SS$_ABORT  External signal only 
SIGQUIT  SS$_CONTROLY  The raise function 
SIGPIPE  SS$_ NOMBX  No mailbox 
SIGSEGV  SS$_ACCVIO  Length violation 
SIGSEGV  SS$_CMODUSER  Change mode user 
SIGSYS  SS$_BADPARAM  Bad argument to system call 
SIGTERM  Not implemented 
SIGTRAP  SS$_BREAK  Breakpoint fault instruction 
SIGUSR1  C$_SIGUSR1  The raise function 
SIGUSR2  C$_SIGUSR2  The raise function 

OpenVMS Alpha Signal-Handling Notes (Alpha only)


Previous Page | Next Page | Table of Contents | Index