Home      Discussion      Topics      Dictionary      Almanac
Signup       Login
Signal (computing)

Signal (computing)

Overview
A signal is a limited form of inter-process communication
Inter-process communication
Inter-process communication is a set of techniques 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 techniques are divided into methods for message passing, synchronization, shared memory, and...

 used in Unix
Unix
Unix is a 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 or "Portable Operating System Interface [for Unix"] is the name of a family of related standards specified by the IEEE to define the application programming interface , along with shell and utilities interfaces for software compatible with variants of the Unix operating system, although the...

-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, consisting of one or more threads, that is being sequentially executed by a computer system that has the ability to run several computer programs concurrently....

 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 functional program are executed or evaluated....

. Execution can be interrupted during any non-atomic instruction
Atomic operation
An atomic operation in computer science refers to a set of operations that can be combined so that they appear to the rest of the system to be a single operation with only two possible outcomes: success or failure.-Conditions:...

. If the process has previously registered a signal handler, that routine is executed.
Discussion
Ask a question about 'Signal (computing)'
Start a new discussion about 'Signal (computing)'
Answer questions from other users
Full Discussion Forum
 
Encyclopedia
A signal is a limited form of inter-process communication
Inter-process communication
Inter-process communication is a set of techniques 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 techniques are divided into methods for message passing, synchronization, shared memory, and...

 used in Unix
Unix
Unix is a 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 or "Portable Operating System Interface [for Unix"] is the name of a family of related standards specified by the IEEE to define the application programming interface , along with shell and utilities interfaces for software compatible with variants of the Unix operating system, although the...

-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, consisting of one or more threads, that is being sequentially executed by a computer system that has the ability to run several computer programs concurrently....

 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 functional program are executed or evaluated....

. Execution can be interrupted during any non-atomic instruction
Atomic operation
An atomic operation in computer science refers to a set of operations that can be combined so that they appear to the rest of the system to be a single operation with only two possible outcomes: success or failure.-Conditions:...

. 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 of a running process causes the system to send it certain signals:
    • Ctrl-C (in older Unices, 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
      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 file signal.h. Symbolic signal names are used because signal numbers can...

      ); 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 dump core. 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 command.)
  • The kill(2) system call
    System call
    In computing, a system call is the mechanism used by an application program to request service from the operating system based on the monolithic kernel or to system servers on operating systems based on the microkernel-structure.- Background :...

     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 request the termination of a process that is currently running on the system.-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* Exception , the second single from Ana Johnsson's second album Little Angel*Exceptional Records...

    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...

     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...

     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 pipeline
    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. Filter programs are often...

    s.

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...

 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.-Etymology:SIG is a common...

.

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 and/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 :...

.

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, consisting of one or more threads, that is being sequentially executed by a computer system that has the ability to run several computer programs concurrently....

 attribute changes. Use of non-reentrant functions, e.g. malloc
Malloc
In computing, malloc is a subroutine for performing dynamic memory allocation in the C and C++ programming languages. It is part of the standard library for both languages. Many implementations of malloc are available, each of which performs differently depending on the computing...

 or printf
Printf
printf functions are a class of functions typically associated with curly bracket programming languages. They accept a string parameter called the format string, which 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, consisting of one or more threads, that is being sequentially executed by a computer system that has the ability to run several computer programs concurrently....

'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. It was the first cache introduced in processors. All current desktop and server processors use a TLB. A TLB has a fixed number of slots that contain page table entries,...

. 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....

. With some exceptions, such as a page fault
Page fault
In computer storage technology, a page is a fixed-length block of memory that is used as a unit of transfer between physical memory and external storage like a disk, and a page fault is an interrupt to the software raised by the hardware, when a program accesses a page that is mapped in address...

, the kernel has sufficient information to fully handle the event and resume the process's execution. In other exceptions, however, the kernel cannot proceed intelligently and 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...

 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
SIGABRT
SIGABRT
On POSIX-compliant platforms, SIGABRT is the signal sent by computer programs to abort the process. In source code, SIGABRT is a symbolic constant defined in the header file signal.h...

Process aborted
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.-Etymology:SIGs is a common...

Signal raised by alarm
Alarm
An alarm gives an audible or visual warning about a problem or condition.Alarms include:* burglar alarms, designed to warn of burglaries; this is often a silent alarm: the police or guards are warned without indication to the burglar, which increases the chances of catching him or her.* alarm...

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.-Etymology:SIG is a common prefix...

Bus error: "access to undefined portion of memory object"
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.On Linux, SIGCLD is a synonym...

Child process terminated, stopped (or continued*)
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...

Continue if stopped
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...

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

Hangup
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
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
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...

Kill (terminate immediately)
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...

Write to pipe with no one reading
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 dump core. 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
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 is a particular error condition that can occur during the operation of computer software...

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.-Etymology:SIG is a common...

Stop executing temporarily
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...

Termination (request to terminate)
SIGTSTP
SIGTSTP
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 file signal.h. Symbolic signal names are used because signal numbers can...

Terminal stop signal
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")
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")
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...

User-defined 1
SIGUSR2 User-defined 2
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...

Pollable event
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.-Etymology:SIG is a common...

Profiling timer expired
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...

Bad syscall
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...

Trace/breakpoint trap
Trap (computing)
In computing and operating systems, a trap is a type of synchronous interrupt typically caused by an exceptional condition in a user process. A trap usually results in a switch to kernel mode, wherein the operating system performs some action before returning control to the originating process...

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...

Urgent data available on socket
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...

Signal raised by timer counting virtual time: "virtual timer expired"
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
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...

File size limit exceeded


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.

External links