Question

I wrote the following (rather stupid) C code:

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



void myHandler(int signum) {

    printf("This will never be printed...\n");

}



int main(int argc, char *argv[]) {

    struct sigaction s1;
    s1.sa_handler=myHandler;

    sigset_t sigs;
    sigfillset(&sigs);
    sigprocmask(SIG_BLOCK, &sigs, NULL);

    sigaction(SIGINT, &s1, NULL);

    while (1) sleep();

    return 1;

}

Now it cannot be killed from terminal!
When I try executing 'kill 4242' from terminal (4242 is the process id), it ignores it!
Of course, my intention was that this process will ignore all signals, but SIGKILL cannot be ignored, can it?
How can I kill this process?

BTW, when running 'ps' from terminal it will not show it on the list:

 4348 pts/8    00:00:00 bash
 4444 pts/8    00:00:00 ps

it will only show it when I run 'ps -u my_username' (along with a bunch others). Does anyone have an idea why?

Was it helpful?

Solution

By default the kill command sends SIGTERM. If you want to kill your program with SIGKILL, use kill -KILL 4242.

Another thing I find handy if a process ignores ^C, just press ^Z, it will suspend the process and give you back the control of the terminal, then you can kill the process with kill %.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top