LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Kill all Background Jobs (http://www.linuxquestions.org/questions/linux-newbie-8/kill-all-background-jobs-227978/)

jwprz70 09-07-2004 11:16 PM

Kill all Background Jobs
 
How do you kill all background jobs? I have tried Kill 0 and Kill -0, and they do not seem to work.

fenderman11111 09-07-2004 11:27 PM

you can't kill a job #, only a pid

so, do 'ps aux' and then find your process... kill the pid of it. it's the big #, more than 3 digits probably...

so like 'kill 2376'

tim1235 09-07-2004 11:53 PM

You can also force a kill with the -9 option

i.e kill -9 2345

chii-chan 09-08-2004 01:43 AM

Use "killall process_name" to kill by name.

jwprz70 09-08-2004 07:46 PM

What if you have multiple background jobs running? The point is I need to be able to kill all background jobs, not individual ones in which I know the PID.

CroMagnon 09-08-2004 09:52 PM

hi jwprz - you can use "jobs -p" to get the process ids of every background job.

then (if you're *sure* you want to kill every job), you can do this:

for x in `jobs -p`; do kill -9 $x; done

The -9 might or might not be necessary depending on your situation.

rjtucke 09-08-2004 09:53 PM

This is as a regular user, right? IE, not as root?
If you give me more info on what exactly you are doing, I will help you code up a perl script to do it. Like, when you say background, does that mean all processes listed under ps -x?

pippet 09-09-2004 01:52 AM

do u want to kill all background jobs of a particular type? for example, all instances of mozilla?
if that is the case use
$killall programmename

phoenix7 09-09-2004 06:51 AM

Hi
you can get programs uid and pid by running
Code:

ps
then you can use
Code:

killall UID
or
Code:

kill PID
if you use '-9' option of kill & killall you can sure about terminating that program

Cheers,
Mohammad

jkastelic 05-08-2010 04:50 PM

Hello!

A more elegant options is to use

Code:

kill -9 $(jobs -p)
Cheers,
Jakob

ksdeepu 05-12-2010 02:29 AM

kill -9 %jobid will do


All times are GMT -5. The time now is 10:45 PM.