信号处理函数前3次捕获SIGKILL

Koh*_* J. -2 c unix signals handler sigkill

我有一个编写信号处理函数的赋值,该函数捕获SIGKILL信号并在前3次调用时显示错误消息.在它第四次处理SIGKILL时,它应该将信号处理程序设置为default,然后将SIGKILL发送到它的进程(它不会捕获).

我想使用循环并在前3次迭代中显示错误消息.我对吗?我很难将SIGKILL发送到它的进程并将处理程序设置为默认值(这让我很困惑).

你能给我建议吗?

shi*_*kou 10

根据man 7 signal,

The signals SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.
Run Code Online (Sandbox Code Playgroud)


Mad*_*Ram 5

他说的是真的,你无法抓住SIGKILL和SIGSTOP

#include <stdio.h>
#include <signal.h>

void funCatch(int signal)
{
    printf("sucessfully caught the kill signal\n");
}

int main(int argc,char **argv)
{
    if(signal(SIGKILL,funCatch)==SIG_ERR)
    {
        printf("cannot catch signal\n");
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这是验证上述语句的示例代码.