Background Jobs
& and jobs.
Some commands take a long time. A big download, or a backup. While they run, your terminal is busy, and you can't type anything else. Unless you send them to the background.

- Some commands take ages
- The terminal is stuck
- Send them to the background
The ampersand
Put an ampersand at the end of a command, and it runs in the background. You get the prompt back straight away. In your own terminal, the shell also prints a job number in brackets, and the PID. Jobs lists what's running in the background, from this terminal.
sleep 300 & jobs [1]+ Running sleep 300 &
Moving jobs around
If a command is already running in the front, press control Z. That pauses it, and puts it in the background, stopped. Then BG lets it carry on in the background. FG brings a job back to the front. And control C stops whatever's in the front.
Background jobs and logging out
Background jobs belong to your terminal. If you close it, they usually stop too. To keep something running after you log out, start it with no hup in front. For serious long running programs, Linux has services, which we'll see soon.
| key | value |
|---|---|
| Close the terminal | jobs usually stop |
| nohup cmd & | keep running |
| Services | for long running programs |
| jobs, fg, bg | manage them |
Summary
An ampersand runs a command in the background, jobs lists them, and FG and BG move them around. Next, stopping processes with kill.
Key takeaways- cmd &
- jobs
- fg, bg, Ctrl+Z