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

时间:2017-10-06 21:10:20

标签: c linux-kernel signals

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

1 个答案:

答案 0 :(得分:1)

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+n时使用SIGRTMIN+n < SIGRTMAX。对其进行编译时检查(即如果您需要的信号多于libc允许的实施信号,则表示您遇到了麻烦)。

e.g。有#define SIGRUBBERDUCK (SIGRTMIN+3)

之类的东西