Linux Signals

Updated: 04/26/2017 by Computer Hope

About Signals

Signals are software interrupts. They are used for inter-process communication in UNIX and UNIX-like operating systems such as Linux.

Signals have been in use since Bell Labs UNIX in the 1970s, and today are formally defined by the POSIX standard.

When a signal is sent to a process, the operating system interrupts the normal flow of the process execution and delivers the notification. If the process has previously registered a way to handle that particular signal, that routine is executed, otherwise the system executes the default signal handler.

Signals can be sent with the kill command.

POSIX Signals

The following signals are part of the POSIX standard. Each signal is a macro defined in the system's <signals.h> header file. They are commonly abbreviated without their SIG- prefix; e.g. SIGHUP is frequently referred to as HUP.

SIGABRT

This signal tells the process to abort operation. ABRT is usually sent by the process itself, when it calls the abort() function of the C programming language to signal an abnormal termination, but it can be sent from any process like any other signal.

SIGALRM, SIGVTALRM and SIGPROF

The ALRM, VTALRM or PROF signal is sent to a process when a time limit specified by a call to an alarm-setting function (such as setitimer) elapses.

ALRM is sent when real or clock time elapses;

VTALRM is sent when CPU time used by the process elapses;

PROF is sent when CPU time used by the process and by the system on behalf of the process elapses.

SIGBUS

The BUS signal is sent to a process when it causes a bus error. The conditions that lead to the signal being raised are, for example, incorrect memory access alignment or non-existent physical address.

SIGCHLD

The CHLD signal is sent to a process when a child process terminates, is interrupted, or resumes after being interrupted. One common usage of the signal is to instruct the operating system to clean up the resources used by a child process after its termination without an explicit call to the wait system call.

SIGCONT

The CONT signal instructs the operating system to restart a process previously paused by the STOP or TSTP signal. One important use of this signal is in job control in the Unix shell.

SIGFPE

The FPE signal is sent to a process when it executes an erroneous arithmetic operation, such as division by zero.

SIGHUP

The HUP signal is sent to a process when its controlling terminal is closed. It was originally designed to notify the process of a serial line drop (HUP stands for "Hang Up"). In modern systems, this signal usually means that the controlling pseudo or virtual terminal has been closed.

SIGILL

The ILL signal is sent to a process when it attempts to execute a malformed, unknown, or privileged instruction.

SIGINT

The INT signal is sent to a process by its controlling terminal when a user wishes to interrupt the process. This signal is typically initiated by pressing Control-C, but on some systems, the "delete" character or "break" key can be used.

SIGKILL

The KILL signal is sent to a process to cause it to terminate immediately. In contrast to SIGTERM and SIGINT, this signal cannot be caught or ignored, and the receiving process cannot perform any clean-up upon receiving this signal.

SIGPIPE

The PIPE signal is sent to a process when it attempts to write to a pipe without a process connected to the other end.

SIGQUIT

The QUIT signal is sent to a process by its controlling terminal when the user requests that the process perform a core dump.

SIGSEGV

The SEGV signal is sent to a process when it makes an invalid virtual memory reference, or segmentation fault, i.e. when it performs a segmentation violation.

SIGSTOP

The STOP signal instructs the operating system to stop a process for later resumption.

SIGTERM

The TERM signal is sent to a process to request its termination. Unlike the KILL signal, it can be caught and interpreted or ignored by the process. This signal allows the process to perform nice termination releasing resources and saving state if appropriate. It should be noted that SIGINT is nearly identical to SIGTERM.

SIGTSTP

The TSTP signal is sent to a process by its controlling terminal to request it to stop temporarily. It is commonly initiated by the user pressing Control-Z. Unlike SIGSTOP, this process can register a signal handler for or ignore the signal.

SIGTTIN and SIGTTOU

The TTIN and TTOU signals are sent to a process when it attempts to read or write respectively from the tty while in the background. Typically, this signal can be received only by processes under job control; daemons do not have controlling terminals and should never receive this signal.

SIGUSR1 and SIGUSR2

The USR1 and USR2 signals are sent to a process to indicate user-defined conditions.

SIGPOLL

The POLL signal is sent to a process when an asynchronous I/O event occurs.

SIGSYS

The SYS signal is sent to a process when it passes a bad argument to a system call.

SIGTRAP

The TRAP signal is sent to a process when a condition arises that a debugger has requested to be informed of — for example, when a particular function is executed, or when a particular variable changes value.

SIGURG

The URG signal is sent to a process when a socket has urgent or out-of-band data available to read.

SIGXCPU

The XCPU signal is sent to a process when it has used up the CPU for a duration that exceeds a certain predetermined user-settable value. The arrival of an XCPU signal provides the receiving process a chance to quickly save any intermediate results and to exit gracefully, before it is terminated by the operating system using the SIGKILL signal.

SIGXFSZ

The XFSZ signal is sent to a process when it grows a file larger than the maximum allowed size.

SIGRTMIN to SIGRTMAX

The RTMIN to RTMAX signals are intended to be used for user-defined purposes. They are real-time signals.

Miscellaneous Signals

The following signals are not standardized by POSIX, but are sometimes used on some systems.

SIGEMT

The EMT signal is sent to a process when an emulator trap occurs.

SIGINFO

The INFO signal is sent to a process when a status request is received from the controlling terminal.

SIGPWR

The PWR signal is sent to a process when the system experiences a power failure.

SIGLOST

The LOST signal is sent to a process when a file lock is lost.

SIGWINCH

The WINCH signal is sent to a process when its controlling terminal changes its size.

Sending Signals from the Keyboard

Signals may be sent from the keyboard. Several standard defaults are listed below. Default key combinations for sending interrupt signals can be defined with the stty command.

Ctrl-C

Send SIGINT (Interrupt). By default, this causes a process to terminate.

Ctrl-Z

Send SIGTSTP (Suspend). By default, this causes a process to suspend all operation.

Ctrl-\

Send SIGQUIT (Quit). By default, this causes a process to terminate immediately and dump the core.

Ctrl-T

Send SIGINFO (Info). By default, this causes the operating system to display information about the command. Not supported on all systems.

Signals Examples

kill -l

List all signals and their numeric equivalents.

kill -9 1234

Send signal 9 (KILL) to process ID 1234.

kill — End a process.
stty — Change terminal line settings.