linux - 当多个信号到达一个进程时,处理信号的进程之间的顺序是什么?

标签 linux algorithm data-structures signals

当多个信号到达一个进程时,处理信号的进程之间的顺序是什么?

什么数据结构用于存储已到达进程但尚未交付的信号?

例如来自APUE

Since the process group is orphaned when the parentterminates, POSIX.1 requires that every process in the newly orphaned process group that is stopped (as our child is) be sent the hang-up signal (SIGHUP) followed by the continue signal (SIGCONT)

This causes the child to be continued, after processing the hang-up signal. The default action for the hang-up signal is to terminate the process, so we have to provide a signal handler to catch the signal. We therefore expect the printf in the sig_hup function to appear before the printf in the pr_ids function.

作为order of SIGCONT and SIGHUP sent to orphaned linux process group说:

The SIGHUP cannot be delivered until the child's execution is resumed. When a process is stopped, all signal delivery is suspended except for SIGCONT and SIGKILL.

So, the SIGHUP does arrive first, but it cannot be processed until the SIGCONT awakens the process execution.

SIGHUPSIGCONT 之前到达停止的进程。 SIGHUP 不能传递,SIGCONT 可以传递。

SIGCONT 是在 SIGHUP 之前还是之后处理的?第一个引号似乎是在说“之后”,而第二个引号似乎是在“直到”之前说“之前”。

如果“之前”:

  • 如何安排 SIGCONT 跳到要传递的 SIGHUP 之前?

  • SIGHUPSIGCONF发送前跳转,如何不被丢弃?

以上是基于一些数据结构实现的,比如FIFO队列或者FILO栈?

谢谢。

最佳答案

不同的实现和 POSIX 实时信号的引入可能会混淆这种情况。 signal(7)表示实时信号与旧式信号的区别在于

实时信号以有保证的顺序传送。多种的 相同类型的实时信号按顺序发送 他们被发送了。如果将不同的实时信号发送到 过程中,他们从最低编号开始交付 信号。 (即,低编号信号具有最高优先级。)通过 相反,如果一个进程有多个标准信号待处理, 它们的交付顺序未指定。

Bach 的“The Design of the Unix Operating System”中描述的旧式信号(在引入 POSIX 实时信号之前)。

要向进程发送信号,内核会在进程表条目的信号字段中设置一个位,对应于接收到的信号类型。 ...当进程从内核模式返回到用户模式时,以及当它以适当低的信号优先级离开 sleep 状态时,内核检查是否收到信号。

您可以在 sched.h 查看一些当前的 linux 数据结构。 .看着这个,我怀疑旧式位图已经消失,位图和链表的组合用于处理旧式和 POSIX 实时信号,但我没有通过足够的代码来确定这一点.

关于linux - 当多个信号到达一个进程时,处理信号的进程之间的顺序是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50635458/

相关文章:

c - 为什么 fcntl() 不阻塞 WSL 中的 F_SETLKW?

linux - 查找一个目录中存在但另一个目录中不存在的文件

linux - Windows 命令类型如何工作

c# - 理解和解决 K-Way 归并排序

c - 如何从c中自定义类型的节点列表中读取数据结构

mySQL:一个条目多个字符串与多个条目

linux - 如何在亚马逊 Linux 上安装 openjdk "1.8.0_20-b26"?

algorithm - 一种路面使用计算算法

python - 具有多种语言的 spaCy 流程文档

与 O-notation 的算法比较