What is the difference between exiting a process via Ctrl+C vs issuing a kill -9 command?
6,512
^C
send the interrupt signal, which can be handled by a program (you can ignore it)
kill -9
send the sigkill signal which kills the program that you can't handle.
That's why you can't kill some programs with ^C
Related videos on Youtube
Comments
-
jshthornton over 1 year
I know I can kill any process with kill -9 command . But sometimes i see that even if I have terminated a program with CTRL+C , the process doesn't get killed . So I want to know the difference between kill -9 vs CTRL+C
-
Gilles 'SO- stop being evil' over 11 years
-
-
vonbrand over 11 yearsOne critical difference is that "well behaved" programs will catch ctrl-C and clean up after themselves (detach from any shared resources, destroy temporary files, reset the terminal to a sane state), SIGKILL doesn't give them that chance. BTW, it can happen that a program is stuck in an unkillable state inside the kernel.
-
ams over 11 years@l0b0:
^C
sendsSIGINT
.kill
(without-9
) sendsSIGTERM
. Both those work the same, and can be handled by the program, but they're independent signals. -
ams over 11 yearsIf
^C
doesn't work then you should trykill
next, and then onlykill -9
if you have to. The difference is thatkill
on it's own gives the program chance to clean up its files and whatnot.kill -9
just removes it without asking nicely. -
l0b0 over 11 yearsAka.
SIGINT
(thanks @ams) andSIGKILL