Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a signal in Unix?

This comment confuses me: "kill -l generally lists all signals". I thought that a signal means a quantized amount of energy.

[Added] Please, clarify the (computational) signal in Unix and the physical signal. Are they totally different concepts?

[Added] Are there major differences between paradigms? Is the meaning the same in languages such as C, Python and Haskell? The signal seems to be a general term.

like image 628
Léo Léopold Hertz 준영 Avatar asked Jan 18 '09 20:01

Léo Léopold Hertz 준영


People also ask

What is signal in UNIX programming?

Signals are software interrupts sent to a program to indicate that an important event has occurred. The events can vary from user requests to illegal memory access errors. Some signals, such as the interrupt signal, indicate that a user has asked the program to do something that is not in the usual flow of control.

What is term signal in Linux?

A signal is an event generated by the UNIX and Linux systems in response to some condition. Upon receipt of a signal, a process may take action. A signal is just like an interrupt; when it is generated at the user level, a call is made to the kernel of the OS, which then acts accordingly.

What is a signal in OS?

A signal is a software generated interrupt that is sent to a process by the OS because of when user press ctrl-c or another process tell something to this process. There are fix set of signals that can be sent to a process. signal are identified by integers.

How signals are generated in Unix?

On Unix systems, there are several ways to send signals to processes—with a kill command, with a keyboard sequence (like control-C), or through your own program (e.g., using a kill command in C).


2 Answers

The manual refers to a very basic mechanism that allow processes or the operation system to notify other processes by sending a signal. The operation system can use it to notify programs about abortions of them (signal SIGABRT) or about a segmentation fault (often caused by accessing a null-pointer, SIGSEGV), to name two of them.

Some unix servers use signals so the administrator can use kill to send them a signal, causing them to re-read their configuration file, without requiring them to restart.

There are default actions taken for some signals and other signals are just ignored. For example on receive of a SIGSEGV, the program terminates, while receiving a SIGCHLD, meaning a child-process died, will by default result in nothing special.

There is a ANSI C standard function that installs a signal handler, which is a function that can execute some code when receiving a signal, called signal (read in man signal). In different unix's, that function behave different, so its usage is discouraged. Its manpage refers to the sigaction function (read man sigaction), which behaves consistent, and is also more powerful.

like image 169
Johannes Schaub - litb Avatar answered Sep 17 '22 19:09

Johannes Schaub - litb


I cannot believe that people are not comparing things such as hardware and software or stressing OS at some points.

Comparison between a signal and an interrupt:

The difference is that while interrupts are sent to the operating system by the hardware, signals are sent to the process by the operating system, or by other processes. Note that signals have nothing to do with software interrupts, which are still sent by the hardware (the CPU itself, in this case). (source)

Definitions

  1. process = a program in execution, according to the book below

Further reading

  1. compare the signal to Interrupts and Exceptions

  2. Tanenbaum's book Modern Operating Systems

like image 45
hhh Avatar answered Sep 17 '22 19:09

hhh