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

问题描述:

我想定义除SIGUSR1和SIGUSR2(或任何其他标准信号)之外的自定义命名信号。 我该如何解决这个问题?在Linux内核中创建您自己的自定义信号

+0

这真的很难,这基本上是不可能的。已经有32个信号,看起来他们必须对应32位'int'中的各个位。当我添加一个时,我不得不篡改现有的一个。但是我开始添加它的地方在'arch/arm/include/asm/signal.h'中(因为我正在研究ARM;它可能是'arch/x86/...')。然后从内核中调用'internal_kill()'将我的信号发送给用户进程。 –

+0

我试图用自定义名称重新定义其中一个信号,但是当我从用户应用程序调用它时,它不能识别信号。即使我正在研究ARM。 – RubberDuck

+0

首先,定义内核源目录中信号名称的头文件可能与普通用户模式C文件在编译时看到的头文件不同。您可能必须手动将这两个单独的头文件实例保持同步。 –

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)

+0

是的,这是我做的,它的工作......谢谢! – RubberDuck