信号是由OS内核还是进程生成的? [英] Are signals generated by OS kernels or processes?

查看:121
本文介绍了信号是由OS内核还是进程生成的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

信号是用于以下目的的进程间通信的有限形式: Unix,类Unix和其他符合POSIX的操作系统.信号 是发送给流程或特定对象的异步通知 线程在同一进程中以便将事件通知给它 发生.

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.

...

内核可以生成信号以将事件通知进程.为了 例如,当进程写入管道时,将生成SIGPIPE 读者已将其关闭;默认情况下,这会导致 进程终止,这在构造shell时很方便 管道.

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?

如果信号是由OS内核生成的,那么在进程间通信中如何使用信号?是否通过将OS内核置于两个通信进程之间的中间来完成操作,即一个进程通过某种方式与OS内核进行通信(也就是信号?),然后OS内核又通过信号与另一个进程进行通信?

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?

推荐答案

信号可以由内核或其他进程发出.在您的示例中,内核本身会生成信号,以便将某些信息传达给进程.

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.

其他进程也可以使用 kill(2) 发送信号内核将信号传递给进程或进程组(进程甚至可以向自身发送信号).如果发起者有权发送信号,则内核将其发送.

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.

这篇关于信号是由OS内核还是进程生成的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆