I have a few Stopped
background processes.
kill $(jobs -p)
and kill `jobs -p`
have no effect
kill %1
, kill %2
, etc. successfully terminate individual processes
How can I kill every background process with one command?
Also, why do the first two commands not work for me?
I'm running Linux Mint 15, 64 bit
Best Answer
When they're running
Seems like you can just do this with
kill
and the output ofjobs -p
.Example
Now I have 3 fake jobs running.
Kill them all like so:
Confirming they're all gone.
When they're stopped
If you have jobs that are stopped, not running you do this instead.
Example
OK so that didn't kill them, but that's because the kill signal cannot be handled by the process itself, it's stopped. So tell the OS to do the killing instead. That's what a
-9
is for.That's better.
When some are running and some are stopped
If you have a mixed bag of processes where some are stopped and some are running you can do a
kill
first followed by akill -9
.Extending the time slightly if you need more to allow for processes to stop themselves first.
Signals
Neither a HUP (-1) or a SIGTERM (-15) to kill will succeed. But why? That's because these signals are kinder in the sense that they're telling the application to terminate itself. But since the application is in a stopped state it can't process these signals. So you're only course is to use a SIGKILL (-9).
You can see all the signals that
kill
provides withkill -l
.If you want to learn even more about the various signals I highly encourage one to take a look at the signals man page,
man 7 signal
.