7

If I begin a process and background it in a terminal window (say ping google.com &), I can kill it using kill %1 (assuming it is job 1).

However if I open another terminal window (or tab) the backgrounded process is not listed under jobs and cannot be killed directly using kill.

Is it possible to kill this process from another terminal window or tab?

Note: I am using the Xfce Terminal Emulator 0.4.3 and bash (although if a solution exists in another common shell but not bash I am open to that as well)

9

Yes, all you need to know is the process id (PID) of the process. You can find this with the ps command, or the pidof command.

kill $(pidof ping)

Should work from any other shell. If it doesn't, you can use ps and grep for ping.

5

If you type top in the another terminal window, it'll list the all the process running. Note the process id of your job there, Then press q to leave that screen. Then kill the process as usual.

  • thanks for your answer but top does not appear to show all the specific processes running in the shell (e.g., it doesn't show ping). It does give me a PID for the terminal emulator but that kills the terminal emulator as you would expect. – KennyPeanuts Dec 11 '12 at 19:51
  • 1
    if you type top -U yourusername in terminal, it'll list only the process that you are using. – arthankamal Dec 12 '12 at 3:25
  • awesome! +1 just for that! thanks – KennyPeanuts Dec 12 '12 at 14:59
  • while in top, hit k then 15 for a soft-kill (try first), 9 for a hard-kill. – Michael Durrant Dec 25 '12 at 4:01
3

I usually do something like this:

ps aux | grep $PROCESS | grep -v grep | awk '{print $2 " " $11}'

For example, if $PROCESS="bash", then this is the output from my current session:

2683 bash
4481 bash
5695 bash

Then I would kill $PID for whichever /bin/bash I no longer want to be running.

ps, grep and (optionally) awk are helpful for hunting down PIDs to kill.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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