Linux Labs

Users, permissions, and processes / Stage 11 of 13

Background jobs and the terminal

Not running Starting usually ~20 s
Leave the lesson

Step 3 of 7 · on a machine · 6 min

Pause and return

A foreground command can be paused and brought back without starting it over.

Exercise · look

Ctrl+Z, jobs, and fg

Start sleep 700, and the prompt disappears. Press Ctrl+Z and run jobs -l. Then bring the wait back with fg and interrupt it with Ctrl+C.

First, predict

What happens to sleep 700 after Ctrl+Z?

Now start the exercise, run the command and compare your prediction with the output.

Sign in and start The machine is available after signing in

Ctrl+Z sends the foreground command a stop signal. The process freezes in state T, like --blog in the previous lesson, and the shell returns the prompt. The job stays in the table, and you can continue it:

Command What it does with the job
fg continues it in the foreground, and the terminal is busy again
bg continues it in the background, and the prompt stays yours

Ctrl+C interrupts the foreground command, and the process ends. ps marks a foreground command with + in the STAT column: ps itself showed R+ in earlier output.

Check yourself 1 question

A long export took over the terminal. You pressed Ctrl+Z and then ran bg. What will jobs show?

  • fg is what takes the terminal again. After bg the job runs in the background and the prompt stays yours.

  • bg continues a stopped job in the background, and jobs shows Running. Stopped would remain after Ctrl+Z alone.

  • bg restarts nothing: the job stays in the table with the same number and PID.

Ctrl+Z pauses the export, and bg continues the same process in the background. The job is Running again, and the terminal is free.

Ubuntu 24.04
Loading…