[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


Signal handling

Signals are invoked, or raised, using the raise() function. When a signal is raised its associated function is executed.

With the Metrowerks C implementation of signal.h a signal can only be invoked through the function "raise", and, in the case of the SIGABRT signal, through the function "abort". When a signal is raised, its signal handling function is executed as a normal function call.

The default signal handler for all signals except SIGTERM is SIG_DFL. The SIG_DFL function aborts a program with the abort() function, while the SIGTERM signal terminates a program normally with the exit() function.

The ANSI C Standard Library specifies that the SIG prefix used by the signal.h macros is reserved for future use. The programmer should avoid using the prefix to prevent conflicts with future specifications of the Standard Library.

The type typedef char sig_atomic_t in signal.h can be accessed as an incorruptible, atomic entity during an asynchronous interrupt.

The number of signals is defined by __signal_max given a value in this header.

Warning: Using unprotected re-entrant functions such as printf(), getchar(), malloc(), etc. functions from within a signal handler is not recommended in any system that can throw signals in hardware. Signals are in effect interrupts, and can happen anywhere, including when you're already within a function. Even functions that protect themselves from re-entry in a multi-threaded case can fail if you re-enter them from a signal handler.
signal.h Signal descriptions:

Macro
Description
SIGABRT  
Abort signal. This macro is defined as a positive integer value. This signal is called by the abort() function.  
SIGFPE  
Floating point exception signal. This macro is defined as a positive integer value.  
SIGILL  
Illegal instruction signal. This macro is defined as a positive integer value.  
SIGINT  
Interactive user interrupt signal. This macro is defined as a positive integer value.  
SIGSEGV  
Segment violation signal. This macro is defined as a positive integer value.  
SIGTERM  
Terminal signal. This macro is defined as a positive integer value. When raised this signal terminates the calling program by calling the exit() function.  

The signal() function specifies how a signal is handled: a signal can be ignored, handled in a default manner, or be handled by a programmer-supplied signal handling function. "Signal function handling arguments" describes the pre-defined signal handling macros.

Signal function handling arguments:

Macro
Description
SIG_IGN  
This macro expands to a pointer to a function that returns void. It is used as a function argument in signal() to designate that a signal be ignored.  
SIG_DFL  
This macro expands to a pointer to a function that returns void. This signal handler quits the program without flushing and closing open streams.  
SIG_ERR  
A macro defined like SIG_IGN and SIG_DFL as a function pointer. This value is returned when signal() cannot honor a request passed to it.  


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: August 16, 2000