How it works...

  1. In step 1, we opened a terminal and created the loop_and_print.sh script. This script merely loops forever, printing as it does.
  2. The following commands will use the loop_and_print.sh script and run in the background as a job. The ps command outputs process information and is piped through grep to simplify the output. In the command, we can see the process ID (PID) next to the username column. Keep note of PIDs so that you can kill zombie processes or stop unnecessary applications:
$ bash loop_and_print.sh &[1]4510$ ps aux | grep loop_and_print.sh # Take note of the PID - write it downrbrash 4510 0.0 0.0 12548 3024 pts/2 S 12:58 0:00 bash loop_and_print.sh
  1. Logging back on and running the ps command will produce zero results. ...

Get Bash Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.