Signal (computing)

Signal (computing)

A signal is a limited form of inter-process communication used in Unix, Unix-like, and other POSIX-compliant operating systems. Essentially it is an asynchronous notification sent to a process in order to notify it of an event that occurred. When a signal is sent to a process, the operating system interrupts the process' normal flow of execution. 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 combinations at the controlling terminal of a running process causes the system to send it certain signals:
** Ctrl-C (in older Unixes, DEL) sends an INT signal (SIGINT); by default, this causes the process to terminate.
** Ctrl-Z sends a TSTP signal (SIGTSTP); by default, this causes the process to suspend execution.
** Ctrl- sends a QUIT signal (SIGQUIT); by default, this causes the process to terminate and dump core.
*The kill(2) system call will send the specified signal to the process, if permissions allow. Similarly, the kill(1) command allows a "user" to send signals to processes. The raise library function sends the specified signal to the "current" process.
*Exceptions such as division by zero or a segmentation violation will generate signals (here, SIGFPE and SIGSEGV respectively, which both cause a core dump by default).
*The kernel can generate a signal to notify the process of an event. For example, SIGPIPE 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.

Handling signals

Signal handlers can be installed with the signal() 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 and SIGSTOP. Signal handling is vulnerable to race conditions. 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() 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.

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 attribute changes. Use of non-reentrant functions, e.g. malloc or printf, inside signal handlers is also unsafe.

Relationship with Hardware Exceptions

A process's execution may result in the generation of a hardware exception, for instance, if the process attempts to divide by zero or incurs a TLB miss. In Unix-like operating systems, this event automatically changes the processor context to start executing a kernel exception handler. With some exceptions, such as a page fault, 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 signal to the process. Similarly, if the process attempted to access a memory address outside of its virtual address space, the kernel would notify the process of this violation via a SIGSEGV 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 specifies the following signals which are defined in <signal.h>::SIGABRT - process aborted:SIGALRM - signal raised by alarm:SIGBUS - bus error: "access to undefined portion of memory object":SIGCHLD - child process terminated, stopped (*or continued):SIGCONT - continue if stopped:SIGFPE - floating point exception: "erroneous arithmetic operation":SIGHUP - hangup:SIGILL - illegal instruction:SIGINT - interrupt:SIGKILL - kill:SIGPIPE - write to pipe with no one reading:SIGQUIT - quit and dump core:SIGSEGV - segmentation violation:SIGSTOP - stop executing temporarily:SIGTERM - termination:SIGTSTP - terminal stop signal:SIGTTIN - background process attempting to read ("in"):SIGTTOU - background process attempting to write ("out"):SIGUSR1 - user defined 1:SIGUSR2 - user defined 2:SIGPOLL - pollable event:SIGPROF - profiling timer expired:SIGSYS - bad syscall:SIGTRAP - trace/breakpoint trap:SIGURG - urgent data available on socket:SIGVTALRM - signal raised by timer counting virtual time: "virtual timer expired":SIGXCPU - CPU time limit exceeded:SIGXFSZ - 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 SUS [] .

ee also


External links

* [ Introduction to Unix Signals Programming]
* [ UNIX and Reliable POSIX Signals] by Baris Simsek
* [ Signal Handlers] by Henning Brauer

Wikimedia Foundation. 2010.

Игры ⚽ Нужен реферат?

Look at other dictionaries:

  • Signal Computing System Architecture — Signal Computing System Architecture,   SCSA …   Universal-Lexikon

  • signal computing system architecture —    (SCSA)    An industry standard architecture from Dialogic Corp. SCSA is an open, non proprietary, specification for developing IVR systems that integrates multiple technologies …   IT glossary of terms, acronyms and abbreviations

  • Signal — Signal, signals, signaling, or signalling may refer to: Scientific concepts * Signal (electrical engineering), a physical quantity that can carry information. * Signal processing, the field of techniques used to extract information from signals * …   Wikipedia

  • Signal integrity — or SI is a measure of the quality of an electrical signal. In digital electronics, a stream of binary values is represented by a voltage (or current) waveform. Over short distances and at low bit rates, a simple conductor can transmit this with… …   Wikipedia

  • Computing — For the formal concept of computation, see computation. For the magazine, see Computing (magazine). For the scientific journal, see Computing (journal). A difference engine: computing the solution to a polynomial function …   Wikipedia

  • Trap (computing) — Kernel trap redirects here. For the website, see KernelTrap. In computing and operating systems, a trap, also known as an exception or a fault, is typically[NB 1][1] a type of synchronous interrupt typically caused by an exceptional condition… …   Wikipedia

  • Sampling (signal processing) — Signal sampling representation. The continuous signal is represented with a green color whereas the discrete samples are in blue. In signal processing, sampling is the reduction of a continuous signal to a discrete signal. A common example is the …   Wikipedia

  • History of computing hardware — Computing hardware is a platform for information processing (block diagram) The history of computing hardware is the record of the ongoing effort to make computer hardware faster, cheaper, and capable of storing more data. Computing hardware… …   Wikipedia

  • Mask (computing) — Signal masking redirects here. For other uses, see Masking (disambiguation). In computer science, a mask is data that is used for bitwise operations. Using a mask, multiple bits in a byte, nibble, word (etc.) can be set either on, off or inverted …   Wikipedia

  • Parallel computing — Programming paradigms Agent oriented Automata based Component based Flow based Pipelined Concatenative Concurrent computing …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”