Professional Documents
Culture Documents
Process Management
Ce•rning Oblective•
this ehcvtet: will be able to:
Understnt.ä ibe concept of a process.
states.
the various stavi* of a prcx•ess, and the transition between these
Define the term process
Expinin operations that can bc performed on processes.
tinderstand the concept ofeoopcrating process.
Provide an overview of interprocess communication.
INTRODUCTION
tn the past. then was a ltmitation of loading only one program at a time into the main memory, for
execuuon. 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 incorporateda 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. Multiprogrammedsystems 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 intercommunicationbetween several processes is referred to as interproeess
communication (IPC).
In this case, the CPU is preempted from the currently running process and allocated to some
another
ready process.
6 • Waiting —+Ready: This transition takes place ifan event (for example, I/O completion, signal
reception, synchronization operation, etc.) for which the process was waiting, has occurred.
New
admitted
event occurs
Ready
Running completion
awaits event or I/O
paging memory management technique has been used) or the segment tables (if segmentation
memory management technique has used). The memory management techniques are
discussed in detail in Chapter 7.
• CPU registers: It stores the contents
etc., at the time when the CPU was last released by the process or preempted
from the process.
• CPU scheduling information.' It includes information used by the scheduling algorithms such
case the priority scheduling is to be used for the process),
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
purposes. These are as follows:
There are different queues available in the system for scheduling
execution, they are massed into a queue called
• •Job queue: As the processes enter the system for
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
Generally, both the ready queue and device queue are maintained as linked lists that contain
of the processes in the queue as their nodes. Each PCB includes a pointer to the PCB oi
the
process in the queue (see Figure 2.2). In addition, the header node of the queue contains pointers
next
the PCBs of the first and last process in the queue. to
NULL
Header
Figure 2.2: Ready Queue and Device Queue Maintainedas Linked List
Whenever a process in the job queue becomes ready to execute, it is brought into the ready
queue
where it waits for CPU allocation. Once the CPU is allocated to it (that is, the process switches
to
the running state), the following transitions may occur:
• If the process needs to perform some I/O operation during its execution, it is removed from
the ready queue and put into the appropriate device queue. After the process completes its
1/0
operation and is ready for execution, it is switched from the device queue to the ready queue.
If an interrupt occurs, the CPU can be forcibly disengaged from the currently executing
process,
the process has to wait until the interrupt is handled. After that, the process is
restoredto
the ready queue.
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.
Ready Queue
3
CPU
child process waits creates new
time slice
terminates process expired
process te inated
Note: In a single processor system,since there can be only one running process at a time, thew is no need
to maintain a queue for 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_orsome 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.
Context Switch
to another demands for saving the context
LTransferring the control of CPU from one process another ready process. This mechanism Of
loading the context of
the currently running process and
switch.jhe portion ofthe process control block
Of
saving and restoring the context is known as context
information, and CPU scheduling information
including the process state, memory management
information) of a process. Context switch
together constitute the context (also called state may
follows:
occur due to a number of reasons some of which are as
system.
• The current process terminates and exits from the
• The time slice of the current process expires.
• The process has to wait for I/O or some other resource.
• Some higher priority process enters the system.
call.
• The process relinquishes the CPU by invoking some system
Context switching is performed in two steps, which are as follows:
l. Save context: In this step, the kernel saves the context of the currently executing process in its
PCB of the process so that it may restore this context ater when its processing is done and the
execution,of the suspended process can be resumed.
2. Restore context: In this step, the kernel loads the saved context of a different process that is to
be executed next. Note that if the process to be executed is newly created and the CPU has not
yet been allocated to it, there will be no saved context. In this case, the kernel loads the context
of the new process. However, if the process to be executed was in waiting state due to temporary
unavailability of I/O or for some other reason, there will be saved context that can be restored.
One of the major drawbacks of using context switching is that it involves a huge cost to the system
in terms of real time and CPU cycles, because the system does not perform any productive work
during switching. Therefore, as far as possible, context switching should be generally refrained from,
otherwise it would amount to sheer waste of time. Figure 2.5 shows context switching between two
processes PI and P2.
Save context
PCB,
PI : ready
Restore context
: ready
PCB
2
PI : ready
: running
Interruptor System call
Save context
PCB2
PI : leady
Restore context : ready
PCB,
PI : running
: ready