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:43

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

查看更多
姐就是有狂的资本
3楼-- · 2019-03-24 19:44

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.

查看更多
Melony?
4楼-- · 2019-03-24 19:45

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

查看更多
Viruses.
5楼-- · 2019-03-24 19:51

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

查看更多
Lonely孤独者°
6楼-- · 2019-03-24 19:54

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.

查看更多
登录 后发表回答