除了 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+n
当SIGRTMIN+n < SIGRTMAX
。对此进行编译时检查(即,如果您需要的信号多于 libc
的实现允许的数量,那么您就有麻烦了)。
例如有类似#define SIGRUBBERDUCK (SIGRTMIN+3)
的东西
关于在 Linux 内核中创建您自己的自定义信号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46613964/