CHP 2 Process Management
CHP 2 Process Management
CHP 2 Process Management
Process Concept
• The process
• Process states
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.
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
Short term
scheduler
New Job
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
CPU Execution
CPU Switch From Process to
Process
End of Chapter 2