25

This is probably a frequently asked question, but I've been unable to find good documentation.

I have jobs running on my system:

foo@fooBox:~/tmp$ jobs
[1]+  Stopped                 foo bar baz

How can I kill this process? I've tried various commands, like kill 1, but it hasn't worked.

3
  • alternatively, $fg [enter] [ctrl-c] :p
    – bubu
    Feb 24, 2011 at 4:00
  • @bubu: That won't work for some programs that catch SIGINT, such as vim.
    – Wuffers
    Feb 24, 2011 at 13:24
  • @Mark Szymanski I knew, I knew :p
    – bubu
    Feb 24, 2011 at 15:23

2 Answers 2

37

You can use the method suggested by @fideli, or you can use the kill command like so:

kill %1

This will kill the first suspended command. You can also find a list of suspended commands like so:

jobs

and it will provide output like such:

[1]+  Stopped                 yes

If you have multiple stopped jobs, the number in brackets ([1]) will be the job number, the one you provide after the % in the kill command.

4
  • This is great! Learned something new about kill.
    – fideli
    Feb 24, 2011 at 6:31
  • 1
    How come I get this -bash: kill: (3593) - Operation not permitted. When I use it with sudo, I get this kill: %1: invalid process id Jul 13, 2014 at 5:56
  • 1
    @CMCDragonkai You've hit a situation where the command you've run is now owned by a different user because you used sudo, so you can't kill it, but running kill using sudo means you no longer have access to your user's job list (try running sudo jobs to see what I mean). Instead, since you now have the PID, simply run sudo kill 3593.
    – morloch
    Mar 25, 2015 at 21:36
  • How can a backgrounded process be owned by another user? Mar 26, 2015 at 12:11
7

If you run ps ax you will get a list of all processes running. Look for the one you want to kill and note the number in the PID column. E.g. say the number was 10203, you would then run:

kill 10203

You can also run ps ax | grep foo to find the exact program you're looking for. Finally, you could run:

killall foo

to kill all instances of foo.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .