Are signals generated by OS kernels or processes?

隐身守侯 提交于 2020-01-15 16:47:49

问题


https://en.wikipedia.org/wiki/Unix_signal says

Signals are a limited form of inter-process communication used in Unix, Unix-like, and other POSIX-compliant operating systems. A signal is an asynchronous notification sent to a process or to a specific thread within the same process in order to notify it of an event that occurred.

...

The kernel can generate signals to notify processes of events. 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.

Are signals generated by OS kernels or processes?

If signals are generated by OS kernels, how are signals used in interprocess communication? Is it done by having OS kernels in the middle between two processes in communication, i.e. a process communicate with a OS kernel via some way (also signals?), and the OS kernel then communicate with the other process via signals?


回答1:


Signals can be originated by either the kernel or other processes. In your example the kernel generates the signal itself in order to communicate something to the process.

Other processes can also send signals using kill(2) which asks the kernel to deliver a signal to a process or to a process group (a process can even send a signal to itself). If the originator has the permissions to send the signal the kernel delivers it.

This is what happens when one runs something like:

$ kill -TERM <some_pid>

Of note is that the kernel is the only entity capable of delivering the signal, regardless of the source.



来源:https://stackoverflow.com/questions/34279464/are-signals-generated-by-os-kernels-or-processes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!