简体   繁体   中英

Is it possible to terminate a program that doesn't respond to signals?

Consider this code

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

void sig_handler(int signum)
{
    printf("Received signal %d\n", signum);
}

int main()
{
    signal(SIGINT, sig_handler);
    signal(SIGTERM, sig_handler);
    signal(SIGHUP, sig_handler);
    signal(SIGQUIT, sig_handler);
    signal(SIGABRT, sig_handler);
    signal(SIGILL, sig_handler);
    signal(SIGKILL, sig_handler);
    signal(SIGFPE, sig_handler);
    signal(SIGSEGV, sig_handler);
    signal(SIGPIPE, sig_handler);
    signal(SIGALRM, sig_handler);
    signal(SIGCHLD, sig_handler);
    signal(SIGUSR1, sig_handler);
    signal(SIGUSR2, sig_handler);
    signal(SIGSTOP, sig_handler);
    sleep(10); 
    return 0;
}

It handles every signal possible. We cannot kill this program using killall program_name .

Is it possible to terminate it without rebooting the computer and how?

As noted in comments, the answer is "no", you cannot construct such a program. The standard ( The Open Group Base Specifications Issue 7 ) lists these signals which cannot be ignored:

  • SIGKILL
  • SIGSTOP

You can't handle SIGKILL so it's possible to terminate the program. Signal are "handed off" to a process by the kernel, so sending a signal from processA to processB employs the kernel. When SIGKILL is delivered to the kernel and doesn't get passed to the process. So the kernel does the job and kill the process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM