Process Management
Process Management
Process Management
Ce•rning Oblective•
this ehcvtet: will be able to:
Understnt.ä ibe concept of a process.
the various stavi* of a prcx•ess, and the transition between these states.
Define the term process
Expinin operations that can bc performed on processes.
tinderstand the concept ofeoopcrating process.
Provide an overview of interprocess communication.
INTRODUCTION
execuuon.
tn the past. then was a ltmitation of loading only one program at a time into the main memory, for program
was multifaceted and very resourceful, as it had access to all the computer resoueces such as memory, CPU time,
1/0 devices, and so on. As time went by, improvements camc thick and fast, with new systems evolving
that incorporated a variety of new and powerful features which dramatically improved the emciency and
functionality of the overall system. Modem computct systems corroborate multiprogramming, which allows a number
of programs to reside in the main memory at the same time. These programs can be executed concurrently, thereby
requiring all svstem resources to be shared among them. Multiprogrammed systems need to distinguish among
the multiple execuung programs, which is accomplished with the concept of a precess (also called task on some
systems).
When multiple processes run on a system concurrently and more than one process requires the CPU at the same time, it
then becomes essential to select any one process to which the CPU can be allocated. Scheduling is required in order to
accomplish this. Moreover, the multiple processes running on a sysÄäii7Eöheed to intercommunicate in order to
reciprocate some data or information. ms kind of intercommunication between several processes is referred to
as interproeess communication (IPC).
2.2 BASIC CONCEPTS
In this section, we will discuss some basic concepts pertaining to processes,
22.1 The Process
As discussed in the previous chapter, a process is a program under execution. In other words, it is an •executing' set of
a system
machine instrucfions. It can be either process executing the system's code or a user process executing the
user's code.
pro
niere a hmrline difference between the process in the sense that a program is a passive entity that does Oot initiate
anything by itself whereas a process is an active entity that performs all the actions specified in particular program, A
process conxprises not only the program
Management
Pmcess 31 code
(known as text section) but also a set of global variables (known as data section) and the
process control block(PCB).
one-to-one
There can be either a one-to-one or a one-to-many relationship between programs and processes. A
relationship exists in case only a singlc program is running on thc system. On the other hand, if multiple instances of a
single program are running simultaneously or when a concurrent program (a program that requires some of its parts
to be executed concurrently) is being run, a one-to-many relationship exists between programs and processes. In this
casc, the text section of the multiple instances will be the same but the data section will be different.
fin important thing worth noting about processes is that some processes involve higher computation than I/O
operations, thereby
CPU
lifetime. Such processes, w ere e s ee o execution is governed by the CPU: are called bound or com u e- oun .
In contrast to this, there are some rocesses that involve a lot of I/O operations as compare to computation during eir
lifetime. Such processes, where the s xecutlon IS governe y e I/O device an not y the CPU, are cal -bound.
admitted
occurs
event Ready
Waiting
interrupt scheduling Terminated
Running
awaits event or I/O completion
• Process state: It.stores the current state of a process that can be new, ready, running, waiting' or terminated.
c D-CCOtt' by OS
Management
Process 33 • Parent process ID: It stores the PID of the parent, if the process has been created by some
other process.
• Child process IDs: It stores the PID s of all the child processes ofa parent process. • Program counter: It contains
thg_addre« of the instruction that is to be executed next in the process. Whenever the
time when the CPU was last allocated to the process, etc. CPU scheduling is discussed in detail in Chapter 4.
• I/O statu_s: It includes information lik
the
Scheduling Queues
There are different queues available in the system for scheduling purposes. These are as follows: • •Job queue: As the processes
enter the system for execution, they are massed into a queue called job queue (or input queue) on a mass storage device such as
a hard disk.
•e Ready queue: From the job queue, the processes which are ready for execution are shifted to the main memory. In the main
memory, these processes are kept in a queue called a ready queue. In other words, the ready queue contains all those processes
that are waiting for the CPU.
• Device queue: A separate queue, called a device queue, is maintained for each I/O device in the system. The process that
needs to perform I/O during its execution is kept in the queue of that specific I/O device and waits there until it is served by
the device.
34
Process anagethent
as linked lists that
Generally, both the ready queue and device queue are maintained contain of the
PCB oi the
processes in the queue as their nodes. Each PCB includes a pointer to the next
queue contains
process in the queue (see Figure 2.2). In addition, the header node of the pointers
Header
the PCBs of the first and last process in the queue. PCB, PCB2
to
PCB
NULL
Figure 2.2: Ready Queue and Device Queue Maintained as Linked List
3. • If the time slice (in case of time sharing systems) of the process has expired, the process is
relegated to the ready queue. • If the process creates a new process and has to wait until the child
process terminates, the parent process is suspended. After the execution ofchild process, it is again
restored to the ready queue. If the process has successfully completed its task, it is terminated. The PCB
and all the resources allocated to the process are de allocated.
All these transitions can be represented with the help of a queuing diagram as shown in Figure 2.3.
process from the job queue
Ready Queue
3
new process
waits CPU child process creates time slice terminates expired
process te inated
Figure 2.3: Queuing Diagram
running
Note: In a single processor system, since there can be only one process at a time, thew is no need to
maintain a queuefor the runningpmcesses.
Process Management
35
'IYpes of Schedulers
The following types of schedulers (see Figure 2.4) may coexist in a complex operating system:
Long-term scheduler: also known as •ob scheduler or admission scheduler it works with the Lob queue. It selects the
next process to be executed from the job queue and loads it into the main memory for execution. The long-term scheduler
must select the processes in such a wa that some
¯cpulz/o
of the rocesses are CP -bound while others are I/O- oun . IS IS ecause if all the processes are CPU-boun , then the
devices will remain unused most of tie time. On the other hand, if all the rocesses are I/O-bound, the CPU will remain
idle most of the time. Thus, to achievthe best pgrformance, a balance mix of CPU-bound and I/O-bound processes must
be selected. The main objective of this scheduler is to control the de _e_ofmultiprogramming (that is, the number o processes
in the ready queue) in order to keep the processor utilization at the desired level. For this, the long-term scheduler
may a It new processes in the ready queue in case GT+ÖÖF processor utilization or may reduce the rate of admission of
processes in the ready queue in case the processor utilization is high. In addition, the long-term scheduler is generally
invoked only when a rocess exits from the of 16KÅLiGö'CheduIer
epends on the system and workload and is much lower than the other two types of schedulers. • Short-term scheduler: also
known as CPU scheduler or rocess scheduler, it selects a process from the ready queue and allocates CPU to lt. IS sc e
u er IS requrre to invoked equen y as compare to ong-term scheduler. This is because generally a process executes
FoFåßfi6ö&hGifÄfter which it may have to wait either f0LUO_or some other reason. At that time, the CPU scheduler
must select some other process and allocate the CPU to it. The CPU scheduler must therefore be fast, so that time ap
between executions is minimized. • Medium-term scheduler: also known as swapper it comes into lay whenever a process
is to be removed from the ready queue (or e In case it is being execut there y re ucmg tue degree of multiprogramming. This
process is stored at some space on the hard disk and later brought into the memory to restart execution from the point
where it left off. This task of switching a process in and out of main memogy is known as swapping (discussed in
detail in Chapter 7). The medium-term scheduler selects a process among the partially executed or unexecuted swapped-
out processes and swaps it in the main memory. The medium-term scheduler•is usually invoked when there is some
unoccupied space in the memory made by the termination of a process or if the supply of ready processes falls below a
specified limit.
: medium-term :
: • scheduler
swap in
swapped-out processes
swap out
short-tems
cheduler
currently executing
process swapped out
Data flow
+
- - Control flow
Job Queue Ready Queue
CPU
Exit
long-term
scheduler
I/O
Device Queue
Operating system
Save context
Processstate
PI . running P2 : ready
PCB,
Restore context
PCB
2
Save context
PCB2
context
Restore PCB,
PI PI
PI PI
: ready
: ready
: ready
: running
: leady
: ready
: running : ready
38
Process
Management
this,
Contrary to this, a process may cause abnormal termination of some another process. For th process invokes an
Window
appropriate system call (for example, Terminateprocess ( ) in % and kill ( ) in UNIX) that tells the operating
process.
system to kill some other Generally, the
happen
parent process can invoke such a system call to terminate its child process. This usually % because of the
following reasons:
• Cascading termination in which the termination (whether normal or forced) Of a process cause; the termination of all
its children. On some operating systems, a child process is not allowed to execute when its parent is being terminated.
operating
In such cases, the system initiates cascading termination.
• The task that was being performe.d by the child process is not required.
• The child process has used up the allocated resources for more than the permissible time.