Whats A Job in Linux: $ Sleep 100 & (1) 1302 $
Whats A Job in Linux: $ Sleep 100 & (1) 1302 $
A job is a process that the shell manages. Each job is assigned a sequential job ID.
Because a job is a process, each job has an associated PID. There are three types of
job statuses:
1. Foreground: When you enter a command in a terminal window, the command
occupies that terminal window until it completes. This is a foreground job.
2. Background: When you enter an ampersand (&) symbol at the end of a
command line, the command runs without occupying the terminal window. The
shell prompt is displayed immediately after you press Return. This is an example of
a background job.
The shell returns the job ID, in brackets, that it assigns to the command and the
associated PID. With the job ID, you can use the job control commands to manage
the job whereas the kernel uses PIDs to manage jobs.
When a background job is complete and you press Return, the shell displays a
message indicating the job is done.
$ jobs
[1]+ Running sleep 100 &
You can use the fg command to bring a background job to the foreground.
$ fg % 1
sleep 100
Note: The foreground job occupies the shell until the job is completed, suspended,
or stopped and placed into the background.
$ sleep 100
^Z
[1]+ Stopped sleep 100
$ jobs
[1]+ Stopped sleep 100
2. Using bg
$ bg % 1
[1]+ sleep 100 &
$ jobs
[1]+ Running sleep 100 &