OS Lab Blue 8
OS Lab Blue 8
LAB 7
This lab will introduce the basic concepts related to process management.
Activity Outcomes:
______________________________________________________________________________
A process is the instance of a computer program that is being executed. While a computer program
is a passive collection of instructions, a process is executing those instructions. Several processes
may be associated with the same program; for example, opening up several instances of the same
program often results in more than one process being executed. When a system starts up, the kernel
initiates a few of its own activities as processes and launches a program called init. init, in turn,
runs a series of shell scripts (located in /etc) called init scripts, which start all the system services.
Many of these services are implemented as daemon programs, programs that just sit in the
background and do their thing without having any user interface. So even if we are not logged in,
the system is at least a little busy performing routine stuff.
The kernel maintains information about each process to help keep things organized. For example,
each process is assigned a number called a process ID or PID. PIDs are assigned in ascending
order, with init always getting PID 1. The kernel also keeps track of the memory assigned to each
process, as well as the processes' readiness to resume execution. Like files, processes also have
owners and user IDs, effective user IDs, etc. In the following, we will discuss the most common
commands; available in Linux to mange processes.
1.1 Displaying Processes in the System
The most commonly used command to view processes is ps. This command displays the processes
for the current shell. We can use the ps command as given below.
We can display all of the processes owned by the current user by using the x option
In the following example, we display processes that are related to the user ubuntu.
Now, we select a process with id 1602
The top command is the traditional way to view your system’s resource usage and see the processes
that are taking up the most system resources. Top displays a list of processes, with the ones using
the most CPU at the top. An improved version of top command is htop but it is usually not
preinstalled in most distributions. When a top program is running, we can highlight the running
programs by pressing z. we can quit the top program by press q or Ctrl + c.
In the following example we display the dynamic view of the system process and resource usage.
“top” command.
The top command in Unix-like operating systems is used to monitor system activity in real-time.
When you run the top command, it displays a dynamic, updating view of system processes,
including information such as CPU usage, memory usage, process IDs (PIDs), user information,
and more.
1.1.3 Displaying processes in Treelike structure
The pstree command is used to display processes in tree-like structure showing the parent/child
The pstree command in Unix-like operating systems is used to display a tree diagram of processes.
It organizes processes into a hierarchical tree structure, where each process is represented as a
node, and child processes are shown nested beneath their parent processes.
1.2 Interrupting A Process
A program can be interrupted by pressing Ctrl + C. This will interrupt the given processes and stop
the process. Ctrl+C essentially sends a SIGINT signal from the controlling terminal to the process,
causing it to be killed.
A foreground process is any command or task you run directly and wait for it to complete. Unlike
with a foreground process, the shell does not have to wait for a background process to end before
it can run more processes. Normally, we start a program by entering its name in the CLI. However,
if we want to start a program in background, we will put an & after its name.
In the following example, first we open the gedit program normally as given below.
It can be noted that gedit is opened as foreground process and control does not returns to terminal
unless it is closed. Now, we start the gedit again as a background process.
It can be seen that after starting the gedit program control returns to the terminal and user can
interact with both terminal and gedit.
The shell's job control facility also gives us a way to list the jobs that have been launched from our
A process in the background is immune from keyboard input, including any attempt to interrupt
it with a Ctrl-c. fg command is used to bring a process to the foreground. In the following
example, we start the gedit editor in background. Then use the jobs command to see the list of
The command fg %1 is used in Unix-like operating systems to bring a background process into
the foreground.
1.6 Killing a process
We can kill a process using the kill command. To kill a process, we provide the process id as an
argument (We could have also specified the process using a jobspec). In the following example,
we start the gedit program and then kill it using kill command.
Every running process in Linux has a priority assigned to it. We can change the process priority
using nice and renice utility. Nice command will launch a process with a user defined scheduling
priority. Renice command will modify the scheduling priority of a running process. In Linux
system priorities are 0 to 139 in which 0 to 99 for real time and 100 to 139 for users. nice value
range is -20 to +19 where -20 is highest, 0 default and +19 is lowest. Relation between nice value
and priority is:
PR = 20 + NI
6. Display the dynamic view of the current processes in the system and set the refresh interval 0.5
second
7. Display the dynamic view of the processes owned by user with id 999 (or name ubuntu)
9. Suspend the gedit program 10. Resume the gedit program Activity 2: