在 Linux 内核中创建您自己的自定义信号

标签 c linux-kernel signals

除了 SIGUSR1 和 SIGUSR2(或任何其他标准信号)之外,我想定义自己的自定义命名信号。 我该怎么办?

最佳答案

http://man7.org/linux/man-pages/man7/signal.7.html指出您可以定义 real time signals - 它们没有预定义的含义。

   The range of supported real-time signals
   is defined by the macros SIGRTMIN and SIGRTMAX.  POSIX.1-2001
   requires that an implementation support at least _POSIX_RTSIG_MAX (8)
   real-time signals.

   The Linux kernel supports a range of 33 different real-time signals,
   numbered 32 to 64.  However, the glibc POSIX threads implementation
   internally uses two (for NPTL) or three (for LinuxThreads) real-time
   signals (see pthreads(7)), and adjusts the value of SIGRTMIN suitably
   (to 34 or 35).  Because the range of available real-time signals
   varies according to the glibc threading implementation (and this
   variation can occur at run time according to the available kernel and
   glibc), and indeed the range of real-time signals varies across UNIX
   systems, programs should never refer to real-time signals using hard-
   coded numbers, but instead should always refer to real-time signals
   using the notation SIGRTMIN+n, and include suitable (run-time) checks
   that SIGRTMIN+n does not exceed SIGRTMAX.

几乎没有什么可添加的:使用 SIGRTMIN+nSIGRTMIN+n < SIGRTMAX 。对此进行编译时检查(即,如果您需要的信号多于 libc 的实现允许的数量,那么您就有麻烦了)。

例如有类似#define SIGRUBBERDUCK (SIGRTMIN+3)的东西

关于在 Linux 内核中创建您自己的自定义信号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46613964/

相关文章:

比较和解释两个时间计数器

linux - 如何开始将现有的cpu调度更改为linux中的组调度

c - 收到 parent 的信号后如何向 child 的 child 发送信号

perl - 如果每个人都使用的调试代码的机制覆盖它,你如何捕获一个有问题的 sig die 处理程序?

c - 收到警报信号时,read() 系统调用不会失败

c - malloc 内存到指向指针的指针

c - 如何在C中打印未指定大小的数组

从 C API 在 Lua 中创建简单列表

linux-kernel - 猜猜0x564c是什么?

linux - `make gtags` 在 Linux 内核上生成空数据库