Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

When I try to exit from my Linux server I get the message:

There are stopped jobs.

: Is there a single command to kill these?

share|improve this question
    
Additional examples in thie U&L Q&A: unix.stackexchange.com/questions/124428/… –  slm Apr 12 at 20:25
    
I had opposite problem now, it would not warn about stopped jobs when I quit the shell! Had to put shopt -s checkjobs in my .bashrc –  Sam Watkins Jul 9 at 5:59

6 Answers 6

up vote 28 down vote accepted

To quickly kill all the jobs running under the bash, enter:

kill `jobs -p`

jobs -p list process ID of the job's. kill `jobs -p` send TERM signal to all jobs.

share|improve this answer
10  
-1 for "kill Jobs" –  Tibor Aug 10 '12 at 21:44
    
didn't work when the job was "sudo su". i.e. sudo kill `jobs -p` didnt work but explicitly typing PID did. –  user13107 Oct 27 '12 at 18:12
3  
Why is this upvoted so highly? It's wrong. If the processes are stopped, then a kill such as this will do nothing, since the processes are stopped, they won't process the SIGTERM (-15) that is sent to them by default. –  slm Apr 12 at 20:18
    
kill -9 will do the trick. –  user371699 Oct 12 at 17:36

If you want to remove some stopped jobs but not all, try this:

First, list jobs, you will get something like this:

$ jobs -l

[2]   4813 Stopped                 ./parse < call.txt
[3]-  4819 Stopped                 ./parse < call.txt

send kill to a stopped job, it will do nothing but queue than bring it in in foreground, it will terminate

$ fg %2
./parse < call.txt
Terminated

$ jobs -l
[3]-  4819 Stopped                 ./parse < call.txt
share|improve this answer
for x in `jobs -p` ; do kill -9 $x ; done
share|improve this answer
2  
you can add code formatting for this line to make it easier to read. –  drcelus Feb 26 '13 at 10:54
    
Can you take a look at your formatting again - use four spaces at the start of the line to mark a block as code (rather than using backtick). Right now it isn't clear whether you are using backticks in your code, or trying to display code using backticks. –  dunxd Feb 26 '13 at 11:39
    
The formatting is fine. we have to pass the jobs -p using backticks else it wont consider as a command, and it will throw an error. –  monu Feb 27 '13 at 6:01

The easiest way is actually to simply immediately retry the exit; bash will take that to mean "kill all stopped jobs and exit".

share|improve this answer
2  
That will send a HUP which doesn't necessarily stop any jobs. –  Stephen Niedzielski Jun 28 at 2:27

The accepted answer would kill all jobs (which is sufficient in this case) and not merely the stopped ones. Should you want to kill only the Stopped ones, run:

kill $(jobs -l | grep Stopped | cut -d' ' -f3)
share|improve this answer

Try typing this:

kill -9 $(jobs -p)
share|improve this answer
7  
That should do it, but I think he should send first a SIGTERM (-15) before sending a SIGKILL (-9). So perhaps proposing something like "kill $(jobs -p) ; sleep 3s ; kill -9 $(jobs -p)" would be better. Sending SIGTERM first the jobs may be able to do a clean exit (freeing allocated resources, etc). –  rems Feb 25 '11 at 10:49
3  
Kevin Duke, your answer is the one that worked for me. I couldn't vote because I don't have 15 in reputation. kill -9 $(jobs -p) –  user131776 Aug 10 '12 at 21:33
    
@rems Except, as slm pointed out, they won't get the SIGTERM because they're stopped. –  Paul Gear Jul 22 at 23:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.