Tell me more ×
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

5 Answers

up vote 18 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 job's.

share|improve this answer
2  
-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

Try typing this:

kill -9 $(jobs -p)
share|improve this answer
2  
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
2  
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

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

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
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 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 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 at 6:01

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.