Chapter 2
Chapter 2
Memory and process
Memory and process
Management
Management
Part 2: Process
management in OS
Prepared by: Nor Zuraida Bt Mohd Gaminan
Department of IT & Communication
Learning Outcome
Learning Outcome
By the end of this chapter, student will be able to:
1)Explain role of control blocks and interrupt in
the dispatching process
2)Describe various types of scheduling processes 3)Explain diferent types of scheduling algorithms 4)Explain how queuing and the scheduler work
together
5)Diferences between multiprogramming and
time sharing
Control blocks
Control blocks
There are several control felds that must be maintained in
support of each active program.
Often, a control block is created to hold:
1)a partition’s key control fags, 2)constants
3) variables
The control blocks (one per partition) are linked to form a linked
list.
The dispatcher typically determines which program is to start by
following the chain of pointers from control block to control block.
A given control block’s relative position in the linked list might
be determined by its priority or computed dynamically, perhaps taking into account such factors as:
1) program size, 2) time in memory,
3) peripheral device requirements
Control blocks
Control blocks
•Information
about each program is stored in the program’s control block.
•The dispatcher
determines which
program to start next by
Interrupts
Interrupts
An interrupt is an electronic signal.
Hardware senses the signal, saves key control information for the currently executing
program, and starts the operating system’s
interrupt handler routine. At that instant, the interrupt ends.
The operating system then handles the interrupt.
Subsequently, after the interrupt is processed, the dispatcher starts an application program. Eventually, the program that was executing at
Example of how interrupt
Example of how interrupt
work
work
Example of how interrupt
Example of how interrupt
work
work
Example of how interrupt
Example of how interrupt
work
work
Example of how interrupt
Example of how interrupt
work
work
Example of how interrupt
Example of how interrupt
work
work
Example of how interrupt
Example of how interrupt
work
work
Process
Process
A program execution, process execution must progress
in sequential fashion
Process include:
1)Program counter 2)Stack
3)Data section
Process state:
- New: The process is being created
- Running: Instruction are being executed
CPU Scheduler
CPU Scheduler
Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them
CPU scheduling decisions may take place when a process:
1. Switches from running to waiting state 2. Switches from running to ready state 3. Switches from waiting to ready
4. Terminates
CPU Scheduler
CPU Scheduler
Preemptive scheduling policy interrupts processing of a
job and transfers the CPU to another job.
- The process may be pre-empted by the operating system when:
1)a new process arrives (perhaps at a higher priority), or 2)an interrupt or signal occurs, or
3)a (frequent) clock interrupt occurs.
Non-preemptive scheduling policy functions without
external interrupts.
- once a process is executing, it will continue to execute until it terminates, or
CPU Scheduling
CPU Scheduling
Scheduling criteria:
1)CPU utilization
The ratio of busy time of the processor to the total time passes for processes to fnish.
Processor Utilization = (Processor buy time) /
(Processor busy time + Processor idle time)
Maximize, to keep as busy as possible
2) Throughput
The measure of work done in a unit time interval.
CPU Scheduling
CPU Scheduling
3) Turnaround time
The sum of time spent in the ready queue, execution time and I/O time.
tat = t(process completed) – t(process submitted)
minimize, time of submission to time of completion. 4) Waiting time
minimize, time spent in ready queue - afected solely by scheduling policy
5) Response time
The amount of time it takes to start responding to a request. This criterion is important for interactive systems.
rt = t(frst response) – t(submission of request)
minimize
CPU Scheduling
CPU Scheduling
Types of scheduling:
1)long-term scheduling
Long-term scheduling
Long-term scheduling
Determine which programs admitted to system for processing - controls degree of
multiprogramming
Once admitted, program becomes a process, either:
– added to queue for short-term scheduler
Medium –term scheduling
Medium –term scheduling
Part of swapping function between main memory and disk
- based on how many processes the OS wants available at any one time
Short –term scheduling
Short –term scheduling
(dispatcher)
(dispatcher)
Executes most frequently, to decide which process to execute next
– Invoked whenever event occurs that interrupts current process or provides an opportunity to preempt current one in favor of another
CPU Scheduling
CPU Scheduling
Types of scheduling algorithm: Basic strategies
1)First In First Out (FIFO) 2)Shortest Job First (SJF)
3)Shortest Remaining Time First (SRTF) 4)Round Robin (RR)
5)Priority
Combined strategies
1)Multi-level queue
First Come First Serve
First Come First Serve
(FIFO)
(FIFO)
Non-preemptive.
Handles jobs according to their arrival time -- the earlier they arrive, the sooner they’re
served.
Simple algorithm to implement -- uses a FIFO queue.
Good for batch systems; not so good for interactive ones.
Shortest Job First (SJF)
Shortest Job First (SJF)
Non-preemptive.
Handles jobs based on length of their CPU cycle time.
◦ Use lengths to schedule process with shortest time.
Optimal – gives minimum average waiting time for a given set of processes.
◦ optimal only when all of jobs are available at same time and the CPU estimates are available and accurate.
Shortest Remaining Time First
Shortest Remaining Time First
(SRTF)
(SRTF)
Preemptive version of the SJF algorithm.
Processor allocated to job closest to completion.
◦ This job can be preempted if a newer job in READY queue has a “time to completion” that's shorter.
Can’t be implemented in interactive system --
requires advance knowledge of CPU time required to fnish each job.
SRT involves more overhead than SJN.
Round Robin (RR)
Round Robin (RR)
FCFS with Preemption.
Used extensively in interactive systems
because it’s easy to implement.
Isn’t based on job characteristics but on a
predetermined slice of time that’s given to each job.
◦ Ensures CPU is equally shared among all active processes and isn’t monopolized by any one job.
Time slice is called a time quantum
Priority scheduling
Priority scheduling
Non-preemptive.
Gives preferential treatment to important jobs.
◦ Programs with highest priority are processed frst.
◦ Aren’t interrupted until CPU cycles are completed or a natural wait occurs.
If 2+ jobs with equal priority are in READY queue, processor is allocated to one that arrived frst
(frst come frst served within priority).
Multi-level feedback queue
Multi-level feedback queue
Multi-level feedback queue
Multi-level feedback queue
Queuing and scheduler
Queuing and scheduler
As one program fnishes processing and space becomes available, which program is loaded into memory next?
This decision typically involves two separate modules, a queuing routine and a
Queuing and scheduler
Queuing and scheduler
1) As programs enter the system, they are placed on a queue by the queuing routine.
Multiprogramming and time
Multiprogramming and time
sharing
sharing
A timesharing system allows multiple users to interact with a computer at the same time
Multiprogramming allowed multiple processes to be active at once, which gave rise to the
ability for programmers to interact with the
computer system directly, while still sharing its resources