Job Control Commands in Linux

marounmaroun profile image Maroun Maroun ・1 min read

Job is simply a process. In Linux, each job is associated with PID.

There are three types of jobs:

Foreground Jobs

When you run vi <file>, the vi program "occupies" the terminal window, and the process runs in the foreground.

When you exit the program, the application is no longer running, and the process dies.

Background Jobs

Processes that are running without occupying the window. This can be achieved, for example, by appending & at the end of the command. For example, when you run:

tar -czf file.tar.gz .

the tar process will block the terminal until it finishes. However, when you run:

tar -czf file.tar.gz . &

then it'll run in the background. And if you type jobs while it's still running:

[1]+  Running                 tar -czf file.tar.gz . &

Stopped Jobs

CTRL + z sends the SIGTSTP signal that stops the job that's runnin in the foreground.

Job Control Commands

  • jobs - lists all jobs
  • bg [PID...] - takes the specified job(s) to the background, resuming them if they are stopped.
  • fg [PID] - brings the specified job to the foreground, resuming it if it is stopped
  • CTRL + z - Sends the SIGTSTP signal that stops the running job

The following should demonstrate the commands above:

> tar -czf file.tar.gz .
# ...working...
# CTRL + z
Job 1, 'tar -czf file.tar.gz .' has stopped
> jobs
[1]+  Running                 tar -czf file.tar.gz . &
> fg %1 (or just "fg" since there's only one job)
# job restarts

That's all :)

Posted on by:

marounmaroun profile

Maroun Maroun


Nice to meet you 🍻 My name is Maroun. I'm a dad, musician, programmer, Stackoverflower and astronaut wannabe.


Editor guide