[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Ctrl-C and normal kill doesn't work.



On Mon, Jun 26, 2000 at 11:47:43AM +0200, Michalowski Thierry wrote:
> Nope.  You will have to understand the "signals" mechanism underlying
> all that.  kill is just a program that sends a signal to a running
> process. Really, it doesn't "kill" anything, it just sends a signal.

Interestingly enough, the C function that it calls is named "kill", so
you could argue that it does kill the process.

> There are a bunch of signals defined on your system, that you can list
> with a 'kill -l' .  When typing Ctrl-C, you're really sending a
> SIGQUIT to the running process. Same when issuing 'kill' without
> argument.

Nope.  You're sending a SIGINT when you type Ctrl-C.  When you issue
kill, you are sending a SIGTERM.

> Usually if not always, it is not possible to ignore SIGKILL (kill -9)
> and SIGTERM (kill -15). Which is why it will kill the processes.  If a
> process is really stuck into a locked state, it won't even be able to
> trap another signal, and thus not end, even if it has been told (by
> the programmer!) to do something like quitting upon receiving a QUIT
> signal. This should explain your case.

It's not possible to ignore SIGKILL or SIGSTOP.  The rest (including
SIGQUIT) may be ignored.

> BTW, there is one case where even kill -9 or kill -15 won't terminate
> a process: when it is stuck in kernel-land and not in userland anymore
> (stuck in a system call that doesn't return). Unfortunately, this is a
> case when you should restart your kernel if you're not able to debug
> it (yeah, means "reboot").

When it's in a "fast" system call, this is the case.  As long as the
machine isn't unusable because of it, it might be better just to wait it
out.

Anyway, you were close with your analysis.  If you want to find out more
about signals, http://www.linux-mag.com should have Eric Troan's very
good articles explaining them posted by now.  

I've also attached a little program which shows how things work.  If you
hit Ctrl-C while it's running, it prints "SIGINT caught", if you use
"kill `pidof sigtest`" on it, it prints "SIGTERM caught", and if you use
"kill -QUIT `pidof sigtest`", then it prints "SIGQUIT caught".

Cheers,
Chris

-- 
pick, pack, pock, puck: like drops of water in a fountain falling
softly in the brimming bowl.
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

void handler(int sig)
{
	if(sig == SIGINT)
		printf("SIGINT caught\n");
	else if(sig == SIGQUIT)
		printf("SIGQUIT caught\n");
	else
		printf("SIGTERM caught\n");
}

int main(void)
{
	struct sigaction sa;

	sa.sa_handler = handler;
	sigemptyset(&sa.sa_mask);
	sa.sa_flags = 0;

	sigaction(SIGINT, &sa, NULL);
	sigaction(SIGQUIT, &sa, NULL);
	sigaction(SIGTERM, &sa, NULL);

	sleep(5);


	return 0;
}

Reply to: