You are on page 1of 12

Background Jobs and Job

Control
Jobs

● A job is a user task run on the computer.


● Reading, sorting etc are the examples of jobs.
● In LINUX, a job is a command or set of
command entered on one command line.
Foreground and background
jobs
● LINUX is a multitasking system.
● To allow multiple task, LINUX defines two types
of jobs:
● Foreground jobs
● Background jobs
Foreground jobs

● What is foreground job?


● Suspending a foreground job: ctrl+z
● To resume it: fg
● Terminating a foreground job: ctrl+c
● After the job is terminated, we key Return to
activate the command line prompt.
Background jobs

● Jobs run in the background free the


keyboard and monitor.
● foreground and background jobs share the
keyboard and monitor.
● Any messages sent to the monitor by the
background job will therefore be mingled
with the messages from the foreground job.
Suspending, Restarting and terminating
background jobs:

● To start a process running in the


background, add an ampersand (&) at the
end of the statement.
● To suspend background job: stop
● To restart it: bg
● To terminate :kill
All three commands require the job number,
prefaced with a percent sign (%).
● When there is only one job, the fg and bg
commands do not require a job number
Moving between background and foreground
jobs:
● To move a job between the foreground and
background, the job must be suspended.
● from the suspended state to the
background with bg command.
● To move a background job to the
foreground, we use fg command.
Jobs command

● To list the current jobs and their status, we


use the jobs command.
● For each job, it shows the job number,
currency, and status, running or stopped.
Currency flag

● + and – signs are called as currency flags.


● The plus indicates which job is default is a
command is entered without a job number.
● The minus indicates which job will be the
default if the first job were to complete.
Using job numbers

● The job number is preceded by a percent


sign(%) and is separated from the
command by one space.
● default job(+) can be referred to as %+ or
%%.
● The job with minus currency can be
referred to as %-.
● All of the following job references are valid:
fg %3 bg%+ stop %% kill %-
Jobs States

● A job may be in one of three states: foreground,


background or stopped
● When job starts, it runs in foreground.
● A terminated job no longer exists.
Process ID

● Job numbers are related to the user session


and the terminal; they are not global.
● Process identifier i.e. PIDs are global in scope.
● ps command displays the current PIDs.