Signal (computing)
Encyclopedia
A signal is a limited form of inter-process communication
Inter-process communication
In computing, Inter-process communication is a set of methods for the exchange of data among multiple threads in one or more processes. Processes may be running on one or more computers connected by a network. IPC methods are divided into methods for message passing, synchronization, shared...

 used in Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

, Unix-like
Unix-like
A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification....

, and other POSIX
POSIX
POSIX , an acronym for "Portable Operating System Interface", is a family of standards specified by the IEEE for maintaining compatibility between operating systems...

-compliant operating systems. Essentially it is an asynchronous notification sent to a process
Process (computing)
In computing, a process is an instance of a computer program that is being executed. It contains the program code and its current activity. Depending on the operating system , a process may be made up of multiple threads of execution that execute instructions concurrently.A computer program is a...

 in order to notify it of an event that occurred. When a signal is sent to a process, the operating system interrupts the process's normal flow of execution
Control flow
In computer science, control flow refers to the order in which the individual statements, instructions, or function calls of an imperative or a declarative program are executed or evaluated....

. Execution can be interrupted during any non-atomic instruction. If the process has previously registered a signal handler, that routine is executed. Otherwise the default signal handler is executed.

Sending signals

  • Typing certain key combinations at the controlling terminal
    Computer terminal
    A computer terminal is an electronic or electromechanical hardware device that is used for entering data into, and displaying data from, a computer or a computing system...

     of a running process causes the system to send it certain signals:
    • Ctrl-C (in older Unixes, DEL) sends an INT signal (SIGINT
      SIGINT (POSIX)
      On POSIX-compliant platforms, SIGINT is the signal sent to a process by its controlling terminal when a user wishes to interrupt the process. In source code, SIGINT is a symbolic constant defined in the header file signal.h...

      ); by default, this causes the process to terminate.
    • Ctrl-Z sends a TSTP signal (SIGTSTP
      SIGTSTP
      SIGTSTP is a signal in a Unix computer system that tells a program to stop temporarily. On POSIX-compliant platforms, SIGTSTP is the signal sent to a process by its controlling terminal when the user requests that the process be suspended. The symbolic constant for SIGTSTP is defined in the header...

      ); by default, this causes the process to suspend execution.
    • Ctrl-\ sends a QUIT signal (SIGQUIT
      SIGQUIT
      On POSIX-compliant platforms, SIGQUIT is the signal sent to a process by its controlling terminal when the user requests that the process perform a core dump. The symbolic constant for SIGQUIT is defined in the header file signal.h; on the vast majority of systems it is signal #3.SIGQUIT can...

      ); by default, this causes the process to terminate and dump core
      Core dump
      In computing, a core dump consists of the recorded state of the working memory of a computer program at a specific time, generally when the program has terminated abnormally...

      .
    • (Those default key combinations can be changed with the stty
      Stty
      The Unix stty command is used for changing the settings of a Unix computer terminal. This command is used to change keystrokes, irregular character handling, and more. Stty gives a full set of features that are also available in ncurses for programmers but simplifies it by building it in to a...

      command.)
  • The kill(2) system call
    System call
    In computing, a system call is how a program requests a service from an operating system's kernel. This may include hardware related services , creating and executing new processes, and communicating with integral kernel services...

     will send the specified signal to the process, if permissions allow. Similarly, the kill(1)
    Kill (Unix)
    In computing, kill is a command that is used in several popular operating systems to send signals to running processes, for example to request the termination of this process.-Unix and Unix-like:...

    command allows a user to send signals to processes. The raise(3) library function sends the specified signal to the current process.
  • Exception
    Exception
    Exception may refer to:* An action that is not part of ordinary operations or standards* Exception handling, in programming languages** or a programming interrupt itself of which exception handling is meant to deal with....

    s such as division by zero or a segmentation violation will generate signals (here, SIGFPE
    SIGFPE
    On POSIX compliant platforms, SIGFPE is the signal sent to a process when it performs an erroneous arithmetic operation. The symbolic constant for SIGFPE is defined in the header file signal.h.- Etymology :...

     and SIGSEGV
    SIGSEGV
    On POSIX-compliant platforms, SIGSEGV is the signal sent to a process when it makes an invalid memory reference, or segmentation fault. The symbolic constant for SIGSEGV is defined in the header file signal.h...

     respectively, which both by default cause a core dump and a program exit).
  • The kernel can generate a signal to notify the process of an event. For example, SIGPIPE
    SIGPIPE
    On POSIX-compliant platforms, SIGPIPE is the signal sent to a process when it attempts to write to a pipe without a process connected to the other end. The symbolic constant for SIGPIPE is defined in the header file signal.h. Symbolic signal names are used because signal numbers can vary across...

     will be generated when a process writes to a pipe which has been closed by the reader; by default, this causes the process to terminate, which is convenient when constructing shell pipelines
    Pipeline (Unix)
    In Unix-like computer operating systems , a pipeline is the original software pipeline: a set of processes chained by their standard streams, so that the output of each process feeds directly as input to the next one. Each connection is implemented by an anonymous pipe...

    .

Handling signals

Signal handlers can be installed with the signal
Sigaction (Unix)
In computing, sigaction is a function API defined by POSIX to give the programmer access to what should be a program's behavior when receiving specific OS signals.- General :...

system call. If a signal handler is not installed for a particular signal, the default handler is used. Otherwise the signal is intercepted and the signal handler is invoked. The process can also specify two default behaviors, without creating a handler: ignore the signal (SIG_IGN) and use the default signal handler (SIG_DFL). There are two signals which cannot be intercepted and handled: SIGKILL
SIGKILL
On POSIX-compliant platforms, SIGKILL is the signal sent to a process to cause it to terminate immediately. The symbolic constant for SIGKILL is defined in the header file signal.h. Symbolic signal names are used because signal numbers can vary across platforms, however on the vast majority of...

 and SIGSTOP
SIGSTOP
On POSIX-compliant platforms, SIGSTOP is the signal sent to a process to stop it for later resumption. The symbolic constant for SIGSTOP is defined in the header file signal.h. Symbolic signal names are used because signal numbers can vary across platforms....

.

Risks

Signal handling is vulnerable to race condition
Race condition
A race condition or race hazard is a flaw in an electronic system or process whereby the output or result of the process is unexpectedly and critically dependent on the sequence or timing of other events...

s. Because signals are asynchronous, another signal (even of the same type) can be delivered to the process during execution of the signal handling routine. The sigprocmask
Sigprocmask (Unix)
In Unix and Unix-like operating systems, sigprocmask is a function call used to change or examine the list of currently blocked signals. Blocked signals are not delivered to the process until unblocked....

call can be used to block and unblock delivery of signals.

Signals can cause the interruption of a system call in progress, leaving it to the application to manage a non-transparent restart
PCLSRing
PCLSRing is the term used in the ITS operating system for a consistency principle in the way one process accesses the state of another process.- Problem scenario :This scenario presents particular complications:...

.

Signal handlers should be written in a way that doesn't result in any unwanted side-effects, e.g. errno alteration, signal mask alteration, signal disposition change, and other global process
Process (computing)
In computing, a process is an instance of a computer program that is being executed. It contains the program code and its current activity. Depending on the operating system , a process may be made up of multiple threads of execution that execute instructions concurrently.A computer program is a...

 attribute changes. Use of non-reentrant functions, e.g. malloc
Malloc
C dynamic memory allocation refers to performing dynamic memory allocation in the C via a group of functions in the C standard library, namely malloc, realloc, calloc and free....

 or printf
Printf
Printf format string refers to a control parameter used by a class of functions typically associated with some types of programming languages. The format string specifies a method for rendering an arbitrary number of varied data type parameter into a string...

, inside signal handlers is also unsafe.

Relationship with Hardware Exceptions

A process
Process (computing)
In computing, a process is an instance of a computer program that is being executed. It contains the program code and its current activity. Depending on the operating system , a process may be made up of multiple threads of execution that execute instructions concurrently.A computer program is a...

's execution may result in the generation of a hardware exception
Exception handling
Exception handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of exceptions, special conditions that change the normal flow of program execution....

, for instance, if the process attempts to divide by zero or incurs a TLB miss
Translation Lookaside Buffer
A translation lookaside buffer is a CPU cache that memory management hardware uses to improve virtual address translation speed. All current desktop and server processors use a TLB to map virtual and physical address spaces, and it is ubiquitous in any hardware which utilizes virtual memory.The...

. In Unix-like
Unix-like
A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification....

 operating systems, this event automatically changes the processor context to start executing a kernel exception handler
Exception handling
Exception handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of exceptions, special conditions that change the normal flow of program execution....

. In case of some exceptions, such as a page fault
Page fault
A page fault is a trap to the software raised by the hardware when a program accesses a page that is mapped in the virtual address space, but not loaded in physical memory. In the typical case the operating system tries to handle the page fault by making the required page accessible at a location...

, the kernel has sufficient information to fully handle the event itself and resume the process's execution. Other exceptions, however, the kernel cannot process intelligently and it must instead defer the exception handling operation to the faulting process. This deferral is achieved via the signal mechanism, wherein the kernel sends to the process a signal corresponding to the current exception. For example, if a process attempted to divide by zero on an x86 CPU, a divide error exception would be generated and cause the kernel to send the SIGFPE
SIGFPE
On POSIX compliant platforms, SIGFPE is the signal sent to a process when it performs an erroneous arithmetic operation. The symbolic constant for SIGFPE is defined in the header file signal.h.- Etymology :...

 signal to the process. Similarly, if the process attempted to access a memory address outside of its virtual address space
Virtual address space
Virtual address space is a memory mapping mechanism available in modern operating systems such as OpenVMS, UNIX, Linux, and Windows NT...

, the kernel would notify the process of this violation via a SIGSEGV
SIGSEGV
On POSIX-compliant platforms, SIGSEGV is the signal sent to a process when it makes an invalid memory reference, or segmentation fault. The symbolic constant for SIGSEGV is defined in the header file signal.h...

 signal. The exact mapping between signal names and exceptions is obviously dependent upon the CPU, since exception types differ between architectures.

List of signals

The Single Unix Specification
Single UNIX Specification
The Single UNIX Specification is the collective name of a family of standards for computer operating systems to qualify for the name "Unix"...

 specifies the following signals which are defined in <signal.h
Signal.h
signal.h is a header file defined in the C Standard Library to specify how a program handles signals while it executes. A signal can report some exceptional behavior within the program , or a signal can report some asynchronous event outside the program .A signal can be generated...

>
:
Signal Description Signal number on Linux x86
SIGABRT
SIGABRT
On POSIX-compliant platforms, SIGABRT is the signal sent to a process to tell itto abort, i.e., to terminate. In source code, SIGABRT is a symbolic constant defined in the header file signal.h...

Process aborted 6
SIGALRM
SIGALRM
On POSIX-compliant platforms, SIGALRM is the signal sent to a process when a time limit has elapsed. The symbolic constant for SIGALRM is defined in the signal.h header file. Symbolic signal names are used because signal numbers can vary across platforms....

Signal raised by alarm
SIGALRM
On POSIX-compliant platforms, SIGALRM is the signal sent to a process when a time limit has elapsed. The symbolic constant for SIGALRM is defined in the signal.h header file. Symbolic signal names are used because signal numbers can vary across platforms....

14
SIGBUS
SIGBUS
On POSIX-compliant platforms, SIGBUS is the signal sent to a process when it causes a bus error. The symbolic constant for SIGBUS is defined in the header file signal.h. Symbolic signal names are used because signal numbers can vary across platforms....

Bus error: "access to undefined portion of memory object" 7
SIGCHLD
SIGCHLD
On POSIX-compliant platforms, SIGCHLD is the signal sent to a process when a child process terminates. The symbolic constant for SIGCHLD is defined in the header file signal.h. Symbolic signal names are used because signal numbers can vary across platforms....

Child process terminated, stopped (or continued*) 17
SIGCONT
SIGCONT
On POSIX-compliant platforms, SIGCONT is the signal sent to restart a process previously paused by the SIGSTOP or SIGTSTP signal. The symbolic constant for SIGCONT is defined in the header file signal.h. Symbolic signal names are used because signal numbers can vary across platforms.-Etymology:SIG...

Continue if stopped 18
SIGFPE
SIGFPE
On POSIX compliant platforms, SIGFPE is the signal sent to a process when it performs an erroneous arithmetic operation. The symbolic constant for SIGFPE is defined in the header file signal.h.- Etymology :...

Floating point exception: "erroneous arithmetic operation" 8
SIGHUP
SIGHUP
On POSIX-compliant platforms, SIGHUP is a signal sent to a process when its controlling terminal is closed....

Hangup 1
SIGILL
SIGILL
On POSIX-compliant platforms, SIGILL is the signal sent to a process when it attempts to execute a malformed, unknown, or privileged instruction. The symbolic constant for SIGILL is defined in the signal.h header file...

Illegal instruction 4
SIGINT
SIGINT (POSIX)
On POSIX-compliant platforms, SIGINT is the signal sent to a process by its controlling terminal when a user wishes to interrupt the process. In source code, SIGINT is a symbolic constant defined in the header file signal.h...

Interrupt 2
SIGKILL
SIGKILL
On POSIX-compliant platforms, SIGKILL is the signal sent to a process to cause it to terminate immediately. The symbolic constant for SIGKILL is defined in the header file signal.h. Symbolic signal names are used because signal numbers can vary across platforms, however on the vast majority of...

Kill (terminate immediately) 9
SIGPIPE
SIGPIPE
On POSIX-compliant platforms, SIGPIPE is the signal sent to a process when it attempts to write to a pipe without a process connected to the other end. The symbolic constant for SIGPIPE is defined in the header file signal.h. Symbolic signal names are used because signal numbers can vary across...

Write to pipe with no one reading 13
SIGQUIT
SIGQUIT
On POSIX-compliant platforms, SIGQUIT is the signal sent to a process by its controlling terminal when the user requests that the process perform a core dump. The symbolic constant for SIGQUIT is defined in the header file signal.h; on the vast majority of systems it is signal #3.SIGQUIT can...

Quit and dump core 3
SIGSEGV
SIGSEGV
On POSIX-compliant platforms, SIGSEGV is the signal sent to a process when it makes an invalid memory reference, or segmentation fault. The symbolic constant for SIGSEGV is defined in the header file signal.h...

Segmentation violation
Segmentation fault
A segmentation fault , bus error or access violation is generally an attempt to access memory that the CPU cannot physically address. It occurs when the hardware notifies an operating system about a memory access violation. The OS kernel then sends a signal to the process which caused the exception...

11
SIGSTOP
SIGSTOP
On POSIX-compliant platforms, SIGSTOP is the signal sent to a process to stop it for later resumption. The symbolic constant for SIGSTOP is defined in the header file signal.h. Symbolic signal names are used because signal numbers can vary across platforms....

Stop executing temporarily 19
SIGTERM
SIGTERM
On POSIX-compliant platforms, SIGTERM is the signal sent to a process to request its termination. The symbolic constant for SIGTERM is defined in the header file signal.h. Symbolic signal names are used because signal numbers can vary across platforms, however on the vast majority of systems,...

Termination (request to terminate) 15
SIGTSTP
SIGTSTP
SIGTSTP is a signal in a Unix computer system that tells a program to stop temporarily. On POSIX-compliant platforms, SIGTSTP is the signal sent to a process by its controlling terminal when the user requests that the process be suspended. The symbolic constant for SIGTSTP is defined in the header...

Terminal stop signal 20
SIGTTIN
SIGTTIN
On POSIX-compliant platforms, SIGTTIN is the signal sent to a process when it attempts to read from the tty while in the background. The symbolic constant for SIGTTIN is defined in the header file signal.h. Symbolic signal names are used because signal numbers can vary across...

Background process attempting to read from tty ("in") 21
SIGTTOU
SIGTTOU
On POSIX-compliant platforms, SIGTTOU is the signal sent to a process when it attempts to write to the tty while in the background. The symbolic constant for SIGTTOU is defined in the header file signal.h. Symbolic signal names are used because signal numbers can vary across...

Background process attempting to write to tty ("out") 22
SIGUSR1
SIGUSR1
On POSIX-compliant platforms, SIGUSR1 and SIGUSR2 are signals sent to a process to indicate user-defined conditions. The symbolic constants for them are defined in the header file signal.h. Symbolic signal names are used because signal numbers can vary across platforms.-Etymology:SIG is a common...

User-defined 1 10
SIGUSR2 User-defined 2 12
SIGPOLL
SIGPOLL
On POSIX-compliant platforms, SIGPOLL is the signal sent to a process when an asynchronous I/O event occurs. The symbolic constant for SIGPOLL is defined in the header file signal.h. Symbolic signal names are used because signal numbers can vary across platforms.On Linux, SIGIO is a synonym for...

Pollable event 29
SIGPROF
SIGPROF
On POSIX-compliant platforms, SIGPROF is the signal sent to a process when the profiling timer expires. The symbolic constant for SIGPROF is defined in the header file signal.h. Symbolic signal names are used because signal numbers can vary across platforms....

Profiling timer expired 27
SIGSYS
SIGSYS
On POSIX-compliant platforms, SIGSYS is the signal sent to a process when it passes a bad argument to a system call. The symbolic constant for SIGSYS is defined in the header file signal.h. Symbolic signal names are used because signal numbers can vary across platforms.-Etymology:SIG is a common...

Bad syscall 31
SIGTRAP
SIGTRAP
On POSIX-compliant platforms, SIGTRAP is the signal sent to a process when a condition arises that a debugger has requested to be informed of. In source code, SIGTRAP is a symbolic constant defined in the header file signal.h. Signal names are used instead of bare numbers because signal numbers can...

Trace/breakpoint trap
Trap (computing)
In computing and operating systems, a trap, also known as an exception or a fault, is typicallyThere is a wide variation in the nomenclature...

5
SIGURG
SIGURG
On POSIX-compliant platforms, SIGURG is the signal sent to a process when a socket has urgent data available to read. In source code, SIGURG is a symbolic constant defined in the header file signal.h. Symbolic signal names are used because signal numbers can vary across platforms.-Etymology:SIG is...

Urgent data available on socket 23
SIGVTALRM
SIGVTALRM
On POSIX-compliant platforms, SIGVTALRM is the signal sent to a process when a time limit has elapsed. In source code, SIGVTALRM is a symbolic constant defined in the header file signal.h. Symbolic signal names are used because signal numbers can vary across platforms.-Etymology:SIG is a common...

Signal raised by timer counting virtual time: "virtual timer expired" 26
SIGXCPU
SIGXCPU
On POSIX-compliant platforms, SIGXCPU is the signal that is sent to a process when it has used up the CPU for a duration that exceeds a certain predetermined user-settable value....

CPU time limit exceeded 24
SIGXFSZ
SIGXFSZ
On POSIX-compliant platforms, SIGXFSZ is the signal sent to a process when it grows a file larger than the maximum allowed size. In source code, SIGXFSZ is a symbolic constant defined in the header file signal.h. Symbolic signal names are used because a signal's designated number can vary across...

File size limit exceeded 25


Note: Where a section is marked by an asterisk, this denotes an X/Open System Interfaces (XSI) extension. Wording in quotes appended with (SUS) denotes the wording from the SUShttp://www.opengroup.org/onlinepubs/007904975.

In addition to signals listed above, a process can send the pseudo-signal 0. This checks for errors as if a signal were sent, without actually sending any, which is useful for e.g. checking if a process exists.

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK