Professional Documents
Culture Documents
Unit3 DrCSYadav
Unit3 DrCSYadav
Greater Noida
Operating System
KCS401
Unit: 3
CPU Scheduling
Dr. C S Yadav
Professor and Head CSE
B Tech 4th Sem
OPERATING SYSTEM(KCS-401)
CODE PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
KCS401.1 3 3 2 2 1 2 - 2 3 2 2 3
KCS401.2 3 3 3 2 2 3 2 2 3 - 1 3
KCS401.3 3 3 2 2 2 2 2 2 2 3 1 3
KCS401.4 3 2 2 3 1 2 2 - 2 - 2 3
KCS401.5 3 1 2 2 2 2 - - 2 2 2 3
KCS401.1 2 1 2 2
KCS401.2 2 2 1 2
KCS401.3 2 3 3 2
KCS401.4 2 2 1 2
KCS401.5 2 2 2 2
• Memory hierarchy
• Cache Organization
• Interrupt
• Registers
• Associative memory
program counter
stack
data section
• Process state
• Program counter
• CPU registers
• Memory-management information
• Accounting information
User Threads
• Examples
•POSIX Pthreads
•Mach C-threads
•Solaris threads
13/05/2020 Dr C S Yadav KCS401 OS Unit Number:3 18
Kernel Threads(CO2)
Kernel Threads
• Supported by the Kernel
• Examples
•Windows 95/98/NT/2000
•Solaris
•Tru64 UNIX
•BeOS
•Linux
• Windows 95/98/NT/2000
• OS/2
• Examples:
4. Terminates.
• switching context
• Max throughput
P1 P2 P3
0 24 27 30
P2 P3 P1
0 3 6 30
• Associate with each process the length of its next CPU burst.
Use these lengths to schedule the process with the shortest
time.
• Two schemes:
• nonpreemptive – once CPU given to the process it cannot
be preempted until completes its CPU burst.
• preemptive – if a new process arrives with CPU burst length
less than remaining time of current executing process,
preempt. This scheme is know as the Shortest-Remaining-
Time-First (SRTF).
• SJF is optimal – gives minimum average waiting time for a
given set of processes.
SJF (non-preemptive)
P1 P3 P2 P4
0 3 7 8 12
SJF (preemptive)
P1 P2 P3 P2 P4 P1
0 2 4 5 7 11 16
• Performance
• q large ≡ FIFO
• q small ≡ q must be large with respect to context switch,
otherwise overhead is too high.
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
• Three queues:
• Q0 – time quantum 8 milliseconds
• Q1 – time quantum 16 milliseconds
• Q2 – FCFS
• Scheduling
• A new job enters queue Q0 which is served FCFS.
When it gains CPU, job receives 8 milliseconds. If it
does not finish in 8 milliseconds, job is moved to
queue Q1.
• At Q1 job is again served FCFS and receives 16
additional milliseconds. If it still does not
complete, it is preempted and moved to queue Q2.
available.
• Homogeneous processors within a multiprocessor.
• Pi requests instance of Rj
Pi
Pi
• Pi is holding an instance of Rj Pi
• Shared entities (read only files) don't need mutual exclusion (and
aren’t susceptible to deadlock.)
Assignment
edge Request
edge
Claim Claim
edge edge
Assignment
edge Request
edge
Assignment
Claim edge
edge
•Multiple instances
•Each process must a priori claim maximum use
•When a process requests a resource it may have to
wait
•When a process gets all its resources it must return
them in a finite amount of time
4.If Finish [i] == true for all i, then the system is in a safe
state
13/05/2020 Dr C S Yadav KCS401 OS Unit Number:3 70
Resource-Request Algorithm for Process Pi(CO3)
Requesti = request vector for process Pi. If Requesti [j] = k then
process Pi wants k instances of resource type Rj
Need
ABC
P0 743
P1 122
P2 600
P3 011
P4 431
• The system is in a safe state since the sequence < P1, P3, P4, P2,
P0> satisfies safety criteria
• Executing safety algorithm shows that sequence < P1, P3, P4, P0,
P2> satisfies safety requirement
• https://www.youtube.com/watch?v=_zOTMOubT1M
• https://www.youtube.com/playlist?list=PLmXKhU9FNesSF
vj6gASuWmQd23Ul5omtD
• https://www.youtube.com/watch?v=x_UpLHXF9dU
• https://www.youtube.com/watch?v=cviEfwtdcEE
• https://nptel.ac.in/courses/106108101
• Define PCB
6. Define PCB.
Draw Gannt chart and find average waiting time and response time
using
• FCFS
• Round Robin (quantum=2)
• SJF and SRTF
•Process Concept
•Process State
•Process Transition Diagram
•Process Control Block (PCB)
•Thread
User thread
Kernel thread
•Single and Multithreaded Processes
•Multithreading Models
Many-to-One
One-to-One
Many-to-Many Model
•Types of Schedulers
•Context Switching
13/05/2020 Dr C S Yadav KCS401 OS Unit Number:3 91
Summary
•CPU Scheduling Algorithms
First Come First Serve(FCFS) Scheduling.
Shortest-Job-First(SJF) Scheduling.
Priority Scheduling.
Round Robin(RR) Scheduling.
Multilevel Queue Scheduling.
Multilevel Feedback Queue Scheduling.
Multiple-Processor Scheduling
Real time scheduling
• Deadlock
• Deadlock characterization
• Deadlock Prevention
• Deadlock Avoidance
• Recovery from Deadlock