15

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.

Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697

11 Answers11

15

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

Community
  • 1
  • 1
hhh
  • 50,788
  • 62
  • 179
  • 282
15

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.

Johannes Schaub - litb
  • 496,577
  • 130
  • 894
  • 1,212
10

A physical signal and a Unix signal are indeed different concepts. When a Unix signal is sent from one process to another, there is no specific corresponding physical signal. Unix signals are merely an abstraction so programmers can talk about processes communicating with one another.

Unix signals could have been called messages, events, notifications, or even a made-up term like "frobs". The designers just chose the name "signal", and it stuck.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • 1
    They could have been called "software interrupts", as well. – Roboprog Aug 28 '09 at 19:31
  • @Roboprog: sorry but this very confusing, look what Tanenbaum writes about the distiction between signal and "software interrupt". He clearly states that `"signals have nothing to do with software interrupts"`. @Greg Hewgill: could you attack the ambiguity? – hhh Apr 08 '11 at 04:29
5

A signal is a message, either to the target process, or to the OS about the target process. It is part of the unix API (and is defined in various POSIX standards).

Read man kill, man signal, and man sigaction.

Other SO questions that might be helpful:

Community
  • 1
  • 1
dmckee --- ex-moderator kitten
  • 98,632
  • 24
  • 142
  • 234
4

Some from my notes :

Allows asynchronous communication

  • Between processes belonging to the same user
  • From the system to any process
  • From the system manager to any process
  • All associated information is in the signal itself
  • Many different signals

SIGINT

  • From the system to all processes associated to a terminal
  • Trigger: ^C pressed
  • Usual way to stop a running process

SIGFPE

  • From the kernel to a single process
  • Trigger: error in floating point operation

SIGKILL

  • To a single process
  • Stops the execution of the destination process

SIGALRM

  • From the kernel to a single process
  • Trigger: timer expiration

SIGTERM

  • To a single process
  • Recommends the process to terminate gracefully

SIGUSR1, SIGUSR2

  • From any process to any other
  • Without a predefined semantic
  • Freely usable by programmers

Sending a signal to another process

  • int kill(pid, signal_ID)

The programmer can decide what to do when a signal is received

  • Use the default behavior
  • Ignore it
  • Execute a user function

Detecting an interrupted write

if (write(fd, buff, SIZE)<0) {
  switch (errno) {
   case EINTR:
    warning(“Interrupted write\n”);
    break;
  }
}…
Codingday
  • 857
  • 6
  • 15
3

A signal is a message which can be sent to a running process.

For example, to tell the Internet Daemon (inetd) to re-read its configuration file, it should be sent a SIGHUP signal.

For example, if the current process ID (PID) of inetd is 1234, you would type: kill -SIGHUP 1234

Paul Lydon
  • 958
  • 6
  • 6
2

A signal is "an event, message, or data structure transmitted between computational processes" (from Wikipedia).

Ben
  • 66,838
  • 37
  • 84
  • 108
1

In this case signal means 'message'. So it's sending a message to a process which can tell the process to do various things.

Greg Leaver
  • 801
  • 6
  • 10
0

Signal is basically an interrupt that tells the process that a particular event has happened.

Signal generally send by the kernel, meanwhile a process can also send the signal to other process (depends on permission ans all ) by using kill and killall command and a process can send signal to itself by using raise.

Major use of signal:

  1. To handle the interrupt.

  2. Process synchronization.

Sandeep_black
  • 1,352
  • 17
  • 18
0

A unix signal is a kind of message that can be sent to and from unix processes. They can do things like tell a process to quit (SIGKILL) or that a process had an invalid memory reference (SIGSEGV) or that the process was killed by the user hitting control-c (SIGINT).

from a *nix command line type in:

man signal

that will should you all the signals available.

hacintosh
  • 3,784
  • 4
  • 19
  • 22
0
  1. Signal is an interrupt that used to intimate a process that a particular event has happened.

  2. Signal can be send by kernel to running process or one process to another process.

  3. In bash kill and killall command used to send the signal.