Backgrounding and foregrounding processes in the Linux terminal
Running commands in the Linux terminal is likely something you do nearly every day, but moving a running process into the “background” and later moving it back into the “foreground” is something different altogether. When a process is running in the foreground (the usual state of running commands), it could be said to “own your terminal”. In other words, you will likely sit and wait for it to finish before you even try to run another command. If a process is likely to take a long time to complete, on the other hand, you do have an option other than waiting patiently for it to get done. You can move it into the background – freeing up your terminal window to run other commands.
Moving a process to the background
To move a process into the background, you would type ^z (hold the Ctrl key and press “z”) to suspend it, and then type bg to move it into the background. The process will keep running, but you’ll get your prompt back and be able to work on something else while it’s still running to completion in the background. Note that a backgrounded process will keep running until it’s done or until you log off. Here’s an example:
$ sleep 1000 ^Z [1]+ Stopped sleep 1000 $ bg [1]+ sleep 1000 &
Checking on backgrounded processes with the jobs command
To list backgrounded processes, use the jobs command like this: