How to determine if a process is running unseen in terminal

processterminal

For ex – if I enter ping one.com the process will keep running – if I want to stop that process, I can type Ctrl C which if I'm not mistaken, will kill the process completely. If instead, I stop it with Ctrl Z, isn't it true that the process can still be operating in the background at some level? How is one able to spot a condition where a process is running but can't be seen on the terminal screen? Thanks.

Best Answer

Use the jobs built-in to see running tasks for your current shell.

$ ping google.com >/dev/null 2>&1 &
[1] 32406

$ jobs
[1]+  Running                 ping google.com > /dev/null 2>&1 &

$ ping google.com
[...]
^Z
[2]+  Stopped                 ping google.com

$ jobs
[1]-  Running                 ping google.com > /dev/null 2>&1 &
[2]+  Stopped                 ping google.com

To kill all running jobs, you can leverage jobs -p which lists the pids of all jobs.

$ for job in $(jobs -p); do kill $job; wait $job; done

Further reading: http://www.tldp.org/LDP/abs/html/x9644.html