signal.h
signal.h es un archivo de cabecera definido en la Biblioteca estándar de C para especificar como un programa maneja señales mientras se ejecuta. Una señal puede reportar un comportamiento excepcional en el programa (tales como la división por cero ), o una señal puede reportar algún evento asíncrono fuera del programa (como alguien está pulsando una tecla de atención interactiva en el teclado)
Una señal puede ser generada llamando a raise
(para enviar una señal al proceso actual) o kill
(para enviar una señal a cualquier proceso). Cada implementación define lo que genera las señales (en su caso) y en qué circunstancias las genera. Una implementación puede definir otras señales además de las que figuran en esta lista. La cabecera estándar <signal.h> pueden definir macros adicionales con nombres que empiezan con SIG para especificar los valores de señales adicionales. Todos los valores son expresiones constantes enteras >= 0.
Un manejador de la señal se puede especificar para todas las señales excepto dos (SIGKILL y SIGSTOP no puede ser atrapadas, bloqueadas o ignoradas). Un manejador de la señal es una función que el entorno de destino llama cuando se produce la señal correspondiente. El entorno de destino suspende la ejecución del programa hasta que vuelva la señal de controlador o llama a longjmp. Para una máxima portabilidad, un manejador de la señal asíncrona sólo debe:
- hacer llamadas (que tienen éxito) a la señal de la función
- asignar valores a los objetos de tipo volátiles
sig_atomic_t
- devolver el control a la función que la llamó
Si la señal informa de un error en el programa (y la señal no es asincrónica), el manejador de la señal puede terminala llamando a abort
, exit
, o longjmp
.
Funciones miembro
int raise(int sig)
. Envía una señal artificialmente.
psignal(int sig, const char *s)
, devuelve a stderr una cadena que representa un número de señal. Esta en 4.3BSD, Solaris y Linux, pero no está especificada por POSIX o SUS.
En los mismos sistemas, string.h contiene la función no estándar strsignal(int sig)
que opera de la misma forma que strerror.
void* signal(int sig, void (*func)(int))
, establece las medidas adoptadas cuando el programa recibe la señalsig
. Si el valor de func es SIG_DFL, se usará el manejo por defecto para esa señal. Si el valor de func es SIG_IGN, la señal será ignorada. De lo contrario se apuntará a una función manejador de señal que se llamará cuando la señar se active.
The function func may terminate by executing a return statement or by calling the abort, exit or longjmp functions. If func executes a return statement, and the value of sig was SIGFPE or any other implementation-defined value corresponding to a computational exception, the behavior is undefined. Otherwise, the program will resume execution at the point it was interrupted. If the function returns and the return request can be honored, the signal function returns the value of func for the most recent call to signal for the specified signal sig. Otherwise a value of SIG_ERR is returned and a positive value is stored in errno.
If the signal occurs other than as the result of calling the abort or raise function, the behavior is undefined if the signal handler calls any function in the standard library other than the signal function itself (with a first argument of the signal number corresponding to the signal that cause the invocation of the handler) or refers to any object with status storage duration other than by assigning to a static storage duration variable of type volatile sig_atomic_t. Furthermore, if such a call to the signal function results in a SIG_ERR return, the value of errno is indeterminate. [1]
Tipos miembro
typedef i-type sig_atomic_t
Macros miembro
- SIG_DFL - Usado para seleccionar el manejo por defecto.
- SIG_IGN - Usado para manejar una señal ignorándola.
- SIG_ERR - Un número usado para errores.
Constantes Miembro
Constante | Significado | Sistemas | |
---|---|---|---|
SIGHUP | Hangup | POSIX | |
SIGINT | Interrupt | ANSI | |
SIGQUIT | Quit | POSIX | |
SIGILL | Illegal instruction | ANSI | |
SIGABRT | Abort | ANSI | |
SIGTRAP | Trace trap | POSIX | |
SIGIOT | IOT trap | 4.2 BSD | |
SIGEMT | EMT trap | 4.2 BSD | |
SIGINFO | Information | 4.2 BSD | |
SIGFPE | Floating-point exception | ANSI | |
SIGKILL | Kill, unblock-able | POSIX | |
SIGBUS | Bus error | 4.2 BSD | |
SIGSEGV | Segmentation violation | ANSI | |
SIGSYS | Bad argument to system call | 4.2 BSD | |
SIGPIPE | Broken pipe | POSIX | |
SIGALRM | Alarm clock | POSIX | |
SIGTERM | Termination | ANSI | |
SIGUSR1 | User-defined signal 1 | POSIX | |
SIGUSR2 | User-defined signal 2 | POSIX | |
SIGCHLD | Child status has changed | POSIX | |
SIGCLD | Same as SIGCHLD | System V | |
SIGPWR | Power failure restart | System V | |
SIGXCPU | Exceeded CPU time | POSIX | |
SIGSTOP | Pause execution | POSIX | |
SIGCONT | Resume execution | POSIX |