What is a signal in Unix?

2019-03-24 19:04发布

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.

11条回答
成全新的幸福
2楼-- · 2019-03-24 19:29

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.

查看更多
我想做一个坏孩纸
3楼-- · 2019-03-24 19:29
  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.

查看更多
The star\"
4楼-- · 2019-03-24 19:33

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.

查看更多
太酷不给撩
5楼-- · 2019-03-24 19:35

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;
  }
}…
查看更多
forever°为你锁心
6楼-- · 2019-03-24 19:39

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

查看更多
唯我独甜
7楼-- · 2019-03-24 19:43

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:

查看更多
登录 后发表回答