2017-10-06 92 views
-1

我想定義除SIGUSR1和SIGUSR2(或任何其他標準信號)之外的自定義命名信號。 我該如何解決這個問題?在Linux內核中創建您自己的自定義信號

+0

這真的很難,這基本上是不可能的。已經有32個信號,看起來他們必須對應32位'int'中的各個位。當我添加一個時,我不得不篡改現有的一個。但是我開始添加它的地方在'arch/arm/include/asm/signal.h'中(因爲我正在研究ARM;它可能是'arch/x86/...')。然後從內核中調用'internal_kill()'將我的信號發送給用戶進程。 –

+0

我試圖用自定義名稱重新定義其中一個信號,但是當我從用戶應用程序調用它時,它不能識別信號。即使我正在研究ARM。 – RubberDuck

+0

首先,定義內核源目錄中信號名稱的頭文件可能與普通用戶模式C文件在編譯時看到的頭文件不同。您可能必須手動將這兩個單獨的頭文件實例保持同步。 –

回答

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+nSIGRTMIN+n < SIGRTMAX。編譯時檢查一下(即如果你需要更多的信號而不是你的實現libc允許,你有麻煩)。

例如有像#define SIGRUBBERDUCK (SIGRTMIN+3)

+0

是的,這是我做的,它的工作......謝謝! – RubberDuck