Download as pdf or txt
Download as pdf or txt
You are on page 1of 30

Chapter 2: Process Management

Process Concept
• The process

• Process states

• Process control block.


Introduction
 A process is a smallest unit of work that is scheduled by O.S
 In multiprogramming environment many processes are present in
memory
 To select the process for execution some management is required .
Hence process management is done by O.S
 It Includes switching the CPU between the processes, select
process for running and so on.
 Process Includes:
 Program counter: includes current activity
 Stack: which contains temp data.
 Data selection: contains global variable
 Text: program code
Process Concept
 An operating system executes a variety of programs:
 Batch system – jobs
 Time-shared systems – user programs or tasks
 Textbook uses the terms job and process almost interchangeably
 Process is a program in execution; process execution must progress in
sequential fashion
 A process includes:
 program counter – includes current activity
 Stack –Which contains temporary data (e.g function parameters, return
addresses and local variables
 data section – contains global variables
 Text – program code
Process in Memory
Process Concept
 Program by itself is not a process. A program is a passive entity such as a file
containing a list of instructions stored on a disk also called as executable file.
 Whereas a process is an active entity with a program counter specifying the
next instruction to execute and a set of associated resources.
 A program becomes a process when an executable file is loaded into memory
 Two common technique for loading executable file are
1) Double-clicking an icon representing the executable file
2) Entering the name of the executable file on the command line.
 Although two processes may be associated with the same program, they are
nevertheless considered two separate executed sequence
e.g - Several user may be running different copies of the mail program, or the
same user may invoke many copies of the web browser program. Each of these
is a separate process and although the text sections are equivalent the data,
heap, and stack sections vary.
Process State
 As a process executes, it changes state
 The state of a process is defined in part by the current activity of that process
 Each process may be in one of the following state
 new: The process is being created
 running: Instructions are being executed
 waiting: The process is waiting for some event to occur
Such as I/O completion or reception of a signal.
 ready: The process is waiting to be assigned to a processor
 terminated: The process has finished execution
Diagram of Process State
Process Control Block (PCB)
 Each process is represented in the O.S by a process control block also called as
task control block
Process Control Block (PCB)
Information associated with each process
 Process state
The state may be new, ready, waiting, halted and so on. This information is
kept in a codified fashion in the PCB. That means it assigns some numbers to each
state and it stores that number so it requires very less space.
 Process number
At the time of process creation O.S allocates a number to the process called
process ID / number
 Program counter
It indicates the address of the next instruction to be executed for this
process.
CPU registers
It vary in no of type depending on the computer architecture. They include
accumulators, index registers, stack pointers, any condition code information. Along
with the program counter the state information must be saved when an interrupt
occurs, to allow the process to be continued correctly afterward
Process Control Block (PCB)
 CPU scheduling information
It includes a process priority, pointer to scheduling queues and any
other scheduling parameters.

 Memory-management information
It includes information as the value of the base and limit registers,
the page tables or the segment tables, depending on the memory system
used by the O.S

 Accounting information
It includes the amount of CPU and real time used time limits,
account numbers, job or process numbers and so on.

 I/O status information


It includes list of I/O devices allocated to the process, a list of open
files and so on.
Process Scheduling
 Scheduling queues

 Schedulers

 context switch
Process Scheduling
• The objective of multiprogramming is to keep CPU busy for maximum time and
achieve maximum CPU Utilization
• In uni-processor system only one process is there and any time it may get the attention
of the CPU
• But in multiprogramming as only one process may get attention of the CPU at a time
other processes have to wait. So the process scheduling is necessary and it is done by
O.S
Scheduling Queues
 As processes enter the system they are put into a job queue, which consists of
all processes in the system
 The processes that are residing in Main Memory(MM) and are ready and
waiting to execute are kept in a list called the ready queue.
 This queue is stored as a linked list
 A ready queue header contains pointers to the first and final PCB’s in the list
 Each PCB includes a pointer field that points to the next PCB in the ready
queue.
Header PCB 2 PCB 9
PCB 7
Tail

 A ready queue need not behave (FIFO) always as a queue in the data
structures. A ready queue may be maintained as a priority queue, stack, tree or
linked list
Ready Queue And Various I/O
Device Queues
Scheduling Queues
• In the system , the processes waiting for CPU are kept in ready queue and the processes
waiting for a device are kept in the device queue.
• A process may have an I/O request and the device requested may be busy
• In such case the I/O request is maintained in the device queue.
• Each device has its own device queue.
• In case of dedicated devices the device queue will never have more process in it
• In case of sharable devices several processes may be in the ready queue.
• Different types of queues :
• Job queue – set of all processes in the system
• Ready queue – set of all processes residing in main memory, ready
and waiting to execute
• Device queues – set of processes waiting for an I/O device

•Processes migrate among the various queues


Representation of Process
Scheduling
Scheduling Queues
• CPU scheduling is represented by a queuing diagram
• Each rectangular box represents a queue.
• Two types of queue are present – the ready queue and device
queue
• Circles represents the resources that serves the queue and
the arrow indicated the flow of processes in the system
• A process that enters the system from outside world is
placed in ready queue. There it waits for CPU
• After the CPU is utilized by the process it may finish its
execution and leave the system or it may need more of I/O
and for that may be placed in the device queue.
Scheduling Queues
• Once the process is allocated the CPU and is executing,
one of several events could occur.

• The process could issue an I/O request and then be


placed in an I/O queue

• The process could create a new sub-process and wait for


the sub-processes termination

• The process could be removed forcibly from the CPU as a


result of an interrupt and be put back in the ready queue.
Functions of Process Scheduling
 Process Scheduling must perform the following function
1.Keep track of the status (running, ready or waiting) of all the process. This is done by
traffic controller
2.The process is selected from ready queue and decided by the scheduler how long it
executes
3.When running process requires any I/O resources or an interrupt occurs or it exceeds
its time quantum the processor de-allocates the process
Schedulers
 A process migrates among the various scheduling queues throughout
its lifetime.
 The O.S must select processes from these queue in some way.
 The selected process is carried out by the appropriate scheduler
 There are 3 different types of scheduler.
1. Long-term scheduler (or job scheduler) – selects which processes
should be brought into the ready queue
2. Short-term scheduler (or CPU scheduler) – selects which process
should be executed next and allocates CPU
3. Medium term scheduling which determines when processes are to be
suspended and resumed;
Addition of Medium Term
Scheduling
Medium term scheduler

Short term
scheduler
New Job

Long term Job Needs


scheduler I/O

Job
finishes
with I/O
Long term Schedulers
 It selects the batch job or process to be executed from a secondary storage device and
loads them into memory for execution.
 It is invoked when the process leaves the system.
 Because of the longer duration between executions LTS can afford to take more time
to decide which process should be selected for execution.
 It also provide good process mix of I/O bound and CPU bound processes to the Short
term scheduler
 The I/O bound process means the process require more I/O than CPU
 The CPU bound process means the process require more CPU then I/O
 If all the processes are CPU bound the I/O waiting queue will almost be empty and if
all processes are I/O bound then ready queue will almost be empty and Short term
scheduler will have little to do
 System with the best performance will have a combination of CPU bound and I/O
bound processes.
Long term Schedulers
 Functions of long term scheduler
1. It communicates directly with the job pool
2. It selects number of jobs from the pool and loads them in
the memory for execution. (degree of multiprogramming is
no. of programs, that can reside in the memory of the
computer at a time)
3. It need to be invoked only when a job leaves the system.
Therefore it is invoked less frequently as compared to short
term scheduler
4. It has the responsibility of selecting proper mix of I/O
bound and CPU bound jobs so that CPU utilization is good.
Short term Schedulers
 It is supposed to select a job from ready queue and submit it
to CPU
 As the STS selects only one job at a time , it is invoked very
frequently
 In case of I/O bound jobs as the ready queue is almost
empty, Short term scheduler has very less work to do.
 The system like time sharing do not have long term
scheduler.
 The jobs are placed directly in the ready queue for the STS .
Medium term Schedulers
 Following are the situations in which medium term scheduler is required
1. Sometimes it is required to remove some number of jobs from memory temporarily
and reduce degree of multiprogramming.
2. Sometimes while executing the program, it is found that memory requirements of the
program are changed. Therefore the job is to be removed from the memory
temporarily.
 Swapping is the process associated with the medium term scheduler by which
processes and temporarily removed and then brought back to the ready queue.
 The dispatcher is the actual component that gives control of the CPU to the process
selected by STS.
Context Switch
 Interrupt cause the O.S to change a CPU from its current task to run a kernel routine.
 The process of switching the CPU from an old process to an new process is called
context switch.
 When interrupt occurs, the system needs to save the current context of the process
currently running on the CPU so that it can restore that context when its processing is
done essentially suspending the process and then resuming it.
 Switching the CPU to another process requires performing a state save of the current
process and a state restore of a different process.
 When a context switch occurs, the kernel saves the context of the old process in its
PCB and loads the saved context of the new process scheduled to run.
 It speed varies from M/C to M/C depending on the memory speed, the no. of
registers that must be copied and the existence of special instruction.
 Typical speeds are a few milliseconds.
 Its times are highly dependent on H/W support.
Context Switch
CPU Execution
Process P0 Interrupt or
System call
occurs

Save its state


into PCB’s Process P2

CPU Execution
CPU Switch From Process to
Process
End of Chapter 2

You might also like