| www.delorie.com/djgpp/doc/libc-2.01/libc_582.html | search |
#include <signal.h> void (*signal(int sig, void (*func)(int)))(int);
Signals are generated in response to some exceptional behavior of the program, such as division by 0. A signal can also report some asynchronous event outside the program, such as someone pressing a Ctrl-Break key combination.
Signals are numbered 0..255 for software interrupts and 256..287 for
exceptions (exception number plus 256); other implementation-specific
codes are specified in <signal.h> (see below). Every signal is
given a mnemonic which you should use for portable programs.
The default handling for all the signals is to print a traceback (a stack dump which describes the sequence of function calls leading to the generation of the signal) and abort the program.
This function allows you to change the default behavior for a specific
signal. It registers func as a signal handler for signal number
sig. After you register your function as the handler for a
particular signal, it will be called when that signal occurs. The
execution of the program will be suspended until the handler returns or
calls longjmp (see section longjmp).
You may pass SIG_DFL as the value of func to reset the signal
handling for the signal sig to default (also
See section __djgpp_exception_toggle, for a quick way to restore all the
signals' handling to default), SIG_ERR to force an error when that
signal happens, or SIG_IGN to ignore that signal. Signal handlers that
you write are regular C functions, and may call any function that the
ANSI/POSIX specs say are valid for signal handlers. For maximum
portability, a handler for hardware interrupts and processor exceptions
should only make calls to signal, assign values to data objects
of type volatile sig_atomic_t (defined as int on
<signal.h>) and return. Handlers for hardware interrupts need
also be locked in memory (so that the operation of virtual memory
mechanism won't swap them out), See section __dpmi_lock_linear_region. Handlers for software interrupts can also
terminate by calling abort, exit or longjmp.
The following signals are defined on <signal.h>:
SIGABRT
assert macro to
terminate the program when an assertion fails (see section assert).
SIGFPE
SIGILL
SIGINT
setmode
(see section setmode), generation of SIGINT as result of Ctrl-C
key is disabled. This is so for programs (such as Emacs) which want to
be able to read the `^C' character as any other character. Use the
library function __djgpp_set_ctrl_c to restore SIGINT
generation when Ctrl-C is hit, if you need this.
See section __djgpp_set_ctrl_c, for details on how this should be done.
Ctrl-Break always generates SIGINT.
DJGPP hooks the keyboard hardware interrupt (Int 09h) to be able to
generate SIGINT in response to Ctrl-C key; you should be
aware of this when you install a handler for the keyboard interrupt.
SIGSEGV
SIGTERM
SIGALRM
alarm library function (see section alarm).
SIGHUP
SIGKILL
SIGPIPE
SIGQUIT
SIGUSR1
SIGUSR2
SIGTRAP
SIGNOFP
SIGTIMR
setitimer and alarm functions
(See section setitimer, See section alarm).
SIGPROF
The previous handler for signal sig, or SIG_ERR if the
value of sig is outside legal limits.
Due to subtle aspects of protected-mode programs operation under MS-DOS,
signal handlers cannot be safely called from hardware interrupt
handlers. Therefore, DJGPP exception-handling mechanism arranges for
the signal handler to be called on the first occasion that the program
is in protected mode and touches any of its data. This means that if
the exception occurs while the processor is in real mode, like when your
program calls some DOS service, the signal handler won't be called until
that call returns. For instance, if you call read (or
scanf, or gets) to read text from the console and press
Ctrl-C, you will have to press Enter to terminate the
read call to cause the signal handler for SIGINT to be
called. Another significant implication of this implementation is that
when the program isn't touching any of its data (like in very tight
loops which only use values in the registers), it cannot be interrupted.
Go to the first, previous, next, last section, table of contents.
| prev next webmaster | delorie software privacy |
| Copyright © 1997 | Updated Apr 1997 |