Linux Tutorials - Herong's Tutorial Examples - v1.32, by Dr. Herong Yang
"jobs" - Manage Background Jobs
Provides a tutorial example on how to use 'jobs' command to display background jobs, which are processes with input detached the keyboard. You can start a background job by adding the 'ampersand' sign to the end of the commmad.
What Is Background Job? - A background job is a process with its input being detached from the keyboard device. Its output may still be attached to the screen.
A foreground job is a process with its input being attached to the keyboard device. When you enter a command at the shell prompt to start a process, it will be started as a foreground job by default. The keyboard will be occupied by this foreground job until it is terminated. So you can only executed 1 process job at any time.
If you want start a process as a background job to keep the keyboard free for the next process, you use the following 2 options:
1. Adding "&" at the end of the command line. This will start the process as a background job immediately. For example, the following command starts a process (ID=40120) as a background job (#=1).
herong$ sleep 100000 &  40120
2. Press "ctrl-z" during the execution of a foreground job. This will stop the foreground job and make it as a background job and keep it as stopped.
herong$ sleep 50000 ctrl-z + Stopped sleep 50000
If you want to see a list of your own background jobs, you can use the "jobs" command:
herong$ jobs - Running sleep 100000 & + Stopped sleep 50000
If you want to resume a stopped job in the background, you can use the "bg #" command:
herong$ bg 2 + sleep 50000 & herong$ jobs - Running sleep 100000 & + Running sleep 50000 &
If you want to bring a background job to the foreground, you can use the "fg" command:
herong$ fg 2 sleep 100000
One nice about running a command in the background is that it will to run, even if your shell session gets disconnected/closed.
Table of Contents