Foreground and Background Jobs

There are two types of jobs. One is a job running as it connects with a terminal – called a foreground job. The other is a job running in the background – called a background job. Understanding these concepts is important for managing multi-tasking jobs.

Foreground Job

When you run a command on a terminal, usually it is executed as a foreground job. As one terminal has only one command line, only one job can be running at the same time.

When you execute only a single command, usually the computer completes the process within a second. This makes it harder for us to see the difference between foreground jobs and background jobs. To see the difference clearly, try a practice task below.

Practice 1

Objective:
Understand how the foreground job works

1. Create a shell script

First, let's create a shell script that requires a longer processing time. The shell script (loop.sh file) below counts down numbers from 1,000,000.

Use vim to