Shell – How to kill a job that was initiated in another shell (terminal window or tab)

job-controljobsprocess-managementshellterminal

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)

Best Answer

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.

Related Question