Controlling Execution Flow
Processes can run in the foreground (interacting with the terminal) or the background (running independently).
Running in the Background (&)
Append an ampersand (&) to a command to launch it in the background immediately, freeing up your terminal.
bash $ sleep 60 & [1] 12345
The number in brackets is the job ID, and the number after is the PID.
Moving from Foreground to Background (Suspend)
- Run a command in the foreground (e.g., a text editor).
- Press
Ctrl + Zto suspend the process. - Type
bg(background) to resume the suspended process in the background.
Moving from Background to Foreground
Use fg (foreground) to bring a background job back to the terminal.
bash $ fg
Brings the most recent background job to the foreground
$ fg %1
Brings job ID 1 to the foreground
Listing Jobs (jobs)
The jobs command shows all processes currently managed by the shell (running or stopped in the background).