3

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.

  • 4
    "I stop it with Ctrl Z, isn't it true that the process can still be operating in the background" — Not usually, no. The process can intercept the signal and perform shenanigans to make itself continue to run, but in general and by default, suspended means suspended, and after Ctrl-Z the process is suspended and not running. – Celada Feb 26 '16 at 22:24
  • 2
    Run the jobs command to see what jobs are in background or suspended – Stéphane Chazelas Feb 26 '16 at 22:29
  • Yes - this seems to be the place to start, will remember - thanks . – bensatlantic Feb 27 '16 at 15:44
7

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

  • In the referenced TLDP.com page, especially see "fg" and "bg". – TOOGAM Feb 27 '16 at 7:11
  • Very helpful - this is what I was looking for - thanks. – bensatlantic Feb 27 '16 at 20:49
1

run ps -aux | grep "processname" to see if process running

run kill "processID" to kill specified process, PID is second set of numbers in previous command in line with target process

run killall "processname" to kill all processes with defined name

  • You can usually also pgrep "process name" to get a list of PIDs matching that name – DopeGhoti Feb 26 '16 at 22:33
  • This is very helpful - I can now spot the ID of the processes and am tuned in to that. Thanks. – bensatlantic Feb 27 '16 at 20:50

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.