How do I end all processes with the same name in a more gentle way than killall
does? I don't want to interrupt the processes, but leave them time to properly quit.
See also:
How do I kill processes in Ubuntu?
In System monitor, what is the difference between Kill Process and End Process?
1. `killall` already nice (SIGTERM)
killall
by default sendsSIGTERM
. This is already the nice approach that leaves applications the chance to clean up after themselves. The "go die already, right now!" approach is to send aSIGKILL
signal, which requires specifying that as an option tokillall
. From The GNU C Library: Termination Signals:2. System Monitor's "End process" equally nice (SIGTERM, too)
You link to a question about GNOME System Monitor. That does use
SIGTERM
for its "End process" action too (and I realise I am contradicting the answer to that question). You can find it in the source code to verify yourself:data/menus.ui:
The 15 here is the signal number. Signal 15 is
SIGTERM
. And System Monitor has usedSIGTERM
well before that other question was asked and answered.Technical addendum (in response to a comment)
Looking through the Github representation of
git blame
, here are the changes that have been made to how the signals are spelt out in the source code of GNOME System Monitor:383007f2 24 Jul 2013 Replaced duplicated code for sending signals with GAction parameters
0e766b2d 18 Jul 2013 Port process popup menu to GAction
97674c79 3 Oct 2012 Get rid of ProcData structure
38c5296c 3 Jul 2011 Make indentation uniform across source files.
None of these changed from
SIGQUIT
toSIGTERM
, and that last one was from before the linked question was asked.The answer by @hvd is basically correct. To back that up even more, the
init
process will first sendSIGTERM
to processes when your are shutting down your computer, then after a delay will sendSIGKILL
if they have not already exited. Processes can't handle/ignoreSIGKILL
.To give a bit more detail though, the real answer is that you have no way of knowing for sure that the program handles it.
SIGTERM
is the most usual signal to use for politely asking a program to quit, but all signal handling depends on the program doing something with the signal.To put it a different way, based on the other answers, if you had a program written by @Jos or by @AlexGreg then they would presumably be handling
SIGQUIT
but possibly notSIGTERM
, and hence sendingSIGTERM
would be less "soft" thanSIGQUIT
.I've written some code so you can play around with it yourself. Save the below as
signal-test.c
, then compile withYou can then run it
./signal-test
, and see what happens when you send different signals withkillall -s <signal>
.As it stands, the code handles both SIGTERM and SIGQUIT gracefully. You could try commenting out the lines
signal(SIG...
(using a//
at the start of the line) to remove the signal handler, then run and send the signals again. You should be able to see these different outputs:depending on whether you handle the signals or not.
You could also try ignoring the signals:
If you do that then sending
SIGTERM
will do nothing, you'll have to useSIGKILL
to end the process.More details in
man 7 signal
. Note that usingsignal()
in this way is considered non-portable - it's lots easier than the alternative though!One other minor footnote - on Solaris
killall
attempts to kill all processes. All of them. If you run it as root then you may be surprised :)"End all" would be
killall -s SIGQUIT [process name]
. If you want a fancy solution, definealias endall='killall -s SIGQUIT'
.