How to manage background tasks in the Bash shell
In the the Bash command line shell the "&" (ampersand) character is a control operator used to fork processes.
According to the man page for Bash:
If a command is terminated by the control operator &, the shell executes the command in the background in a subshell. The shell does not wait for the command to finish, and the return status is 0.
If the ampersand character is added to the end of a command, Bash will execute the command as a background process and assign a Job Number in addition to the usual Process ID (PID) to it:
Willem-Van-Zyls-MacBook-Pro:~ willem$ sleep 60 &
[1] 66984
Willem-Van-Zyls-MacBook-Pro:~ willem$ sleep 30 &
[2] 67001
In the above output, the "[1]" and "[2]" indicate the Job Numbers and the "66984" and "67001" indicate the PIDs.
To see a list of all running jobs, use the "jobs" command:
Willem-Van-Zyls-MacBook-Pro:~ willem$ jobs
[1]- Running sleep 60 &
[2]+ Running sleep 30 &
To terminate a job, use the "kill" command and a "%" (percentage sign) with the Job Number appended:
kill %1