0% found this document useful (0 votes)
2 views5 pages

Understanding The Process

The document explains job control commands in Linux, detailing the types of jobs (foreground, background, and stopped) and how to manage them using commands like jobs, bg, and fg. It also covers utilities like top, ps, kill, df, and free for monitoring processes and system resources. Key concepts include process IDs (PIDs), job IDs, and the priority index known as Nice.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views5 pages

Understanding The Process

The document explains job control commands in Linux, detailing the types of jobs (foreground, background, and stopped) and how to manage them using commands like jobs, bg, and fg. It also covers utilities like top, ps, kill, df, and free for monitoring processes and system resources. Key concepts include process IDs (PIDs), job IDs, and the priority index known as Nice.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Understanding the Process/job control commands in

Linux

Whats a job in Linux

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.
3. Stopped: If you press Control + Z for a foreground job, or enter the stop command for a
background job, the job stops. This job is called a stopped job.

Job Control Commands

Job control commands enable you to place jobs in the foreground or background, and to start or stop
jobs. The table describes the job control commands.

Option Description

jobs Lists all jobs

bg % n Places the current or specified job in the background, where n is the job ID

fg % n Brings the current or specified job into the foreground, where n is the job ID

Control-Z Stops the foreground job and places it in the background as a stopped job

Note: The job control commands enable you to run and manage multiple jobs within a shell. However,
you can use the job control commands only in the shell where the job was initiated.

Running a Job in the Background

To run a job in the background, you need to enter the command that you want to run, followed by
an ampersand (&) symbol at the end of the command line. For example, run the sleep command in
the background.

$ sleep 100 &


[1] 1302
$
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.

[1] + Done sleep 100 &


$

Managing the background jobs

You can use the jobs command to list the jobs that are currently running or suspended in the
background.

$ 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.

You can use the ‘Control+Z keys and bg command to return a job to the background. The Control+Z
keys suspend the job, and place it in the background as a stopped job. The bg command runs the job
in the background. For example:
1. Using CTRL+Z

$ 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 &

Note: When you place a stopped job either in the foreground or background, the job restarts.
Top Command
This utility tells the user about all the running processes on the Linux machine.

Press 'q' on the keyboard to move out of the process display.

The terminology follows:

Field Description Example 1 Example 2


PID The process ID of each task 1525 961
User The username of task owner Home Root
PR Priority Can be 20(highest) or -20(lowest) 20 20
NI The nice value of a task 0 0
VIRT Virtual memory used (kb) 1775 75972
RES Physical memory used (kb) 100 51
SHR Shared memory used (kb) 28 7952
Status
There are five types:
'D' = uninterruptible sleep
S 'R' = running S R
'S' = sleeping
'T' = traced or stopped
'Z' = zombie
%CPU % of CPU time 1.7 1.0
%MEM Physical memory used 10 5.1
TIME+ Total CPU time 5:05.34 2:23.42
Command Command name [Link] Xorg

PS
This command stands for 'Process Status'. It is similar to the "Task Manager" that pop-ups in a Windows
Machine when we use Cntrl+Alt+Del. This command is similar to 'top' command but the information
displayed is different.
To check all the processes running under a user, use the command -

ps ux

You can also check the process status of a single process, use the syntax -

ps PID

Kill
This command terminates running processes on a Linux machine. To use these utilities you need to know
the PID (process id) of the process you want to kill

Syntax -

kill PID

To find the PID of a process simply type

pidof Process name

Let us try it with an example.


DF
This utility reports the free disk space(Hard Disk) on all the file systems.

If you want the above information in a readable format, then use the command

'df -h'

Free
This command shows the free and used memory (RAM) on the Linux system.

You can use the arguments

free -m to display output in MB

free -g to display output in GB

Summary:
 Any running program or a command given to a Linux system is called a process
 A process could run in foreground or background
 The priority index of a process is called Nice in Linux. Its default value is 0, and it can vary between
20 to -19
 The lower the Niceness index, the higher would be priority given to that task

You might also like