0% found this document useful (0 votes)
22 views4 pages

Process Scheduling and Policies Explained

The document outlines process scheduling in operating systems, detailing the three primary states: Ready, Running, and Waiting. It discusses various scheduling policies including First-Come-First-Served, Shortest-Job-First, and Priority Scheduling, along with their advantages and disadvantages. Additionally, it covers concepts like preemptive and non-preemptive scheduling, as well as the Round-Robin and Multi-level Feedback Queue approaches.

Uploaded by

Ishan Khan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views4 pages

Process Scheduling and Policies Explained

The document outlines process scheduling in operating systems, detailing the three primary states: Ready, Running, and Waiting. It discusses various scheduling policies including First-Come-First-Served, Shortest-Job-First, and Priority Scheduling, along with their advantages and disadvantages. Additionally, it covers concepts like preemptive and non-preemptive scheduling, as well as the Round-Robin and Multi-level Feedback Queue approaches.

Uploaded by

Ishan Khan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Processes and State Transitions

Ready
Ready Running
Running
Head

Tail
ready queue Waiting
Waiting

Head
Tail
Process Scheduling
resource/synchronization queues

Three states: Ready, Running, and Waiting


When
Whenaaprocess
processmakes
makesaatransition:
transition: Why
Whyaaprocess
processmakes
makesaatransition:
transition:
fromrunning
[Link] runningtotowaiting
waiting
2. from running to ready
[Link]
anaction
actionof theprocess
ofthe process
2. from running to ready non-preemptive
non-preemptivescheduling
scheduling
3. fromwaiting
[Link] toready
waitingto ready 2.
[Link]
occurrenceof
ofan externalevent
anexternal event
preemptive
preemptivescheduling
(3 processisiscreated
(3aa. .aaprocess created)) scheduling
4. from running to terminated
4. from running to terminated
1 2

Scheduling Policies
Process Scheduling First-Come-First-Served (FCFS)

Process scheduling The discipline corresponding to FIFO queuing

ÿ Select a process from ready Example — 3 processes w/ compute times 12, 3, and 3
queue for execution ÿ Job arrival order P1, P2 , P3

Evaluation metrics
Execution PP1 PP2 PP3
1 2 3
ÿ CPU/device utilization Ready
Ready Running
Running Time 0 12 15 18
Average response time = ( 12 + 15 + 18 )/3 = 15
ÿ System throughput
ready Waiting
Waiting
queue
Job arrival order P2, P3, P1
ÿ Waiting time
Execution PP2 PP3 PP1
2 3 1
ÿ Response time Time 0 3 6 18
synchronization queues
Average response time = ( 3 + 6 + 18 ) /3 = 9
3 4
Scheduling Policies
FCFS Scheduling (Cont’d.) Shortest-Job-First (SJF)

Advantage: Select the shortest job first


ÿ Simple ÿ Enqueue jobs in order of estimated completion time

Disadvantages:
ÿ Average waiting time is highly variable
Head Pw, c = 9
v Short jobs may wait behind long ones !!
ÿ May lead to poor overlap between I/O and CPU processing Px, c = 12
Ready
Ready Running
Running
v CPU bound processes will make I/O bounds processes to wait fi
I/O devices remain idle
Py, c = 34
Tail Pz, c = 62 Waiting
Waiting
ready
queue

semaphore/condition queues
5 6

Shortest-Job-First Scheduling
An optimal policy for minimizing response times SJF Scheduling --- The Catch

Intuition: Consider an SJF execution of a set of processes It’s unfair !!


ÿ Continuous stream of short jobs will starve long jobs
Average response time = (r1 + r2 + r3 + r4 + r5 + r6)/6
SJF: PP11 PP22 PP3 PP4 PP5 PP6 Needs clairvoyance
3 4 5 6
0 r1 r2 r3 r4 r5 r6 ÿ Need to know the execution time of a process
ÿ Simple solution: ask the user !
Can switching the execution order reduce response time? ÿ Yeah, right !!

XYZ: PP11 PP22 PP4 PP5 PP3 PP6 So, what if you don’t subscribe to the Psychic Network ??
4 5 3 6
0 r1 r2 r4 – c3 r5 – c3 r3+c 4+c 5 r6
Average response
time = (r1 + r2 + r4–c3 + r5–c3 + r4+c4+c5 + r6)/6
= (r1 + r2 + r3 + r4 + r5 + r6 + (c4+c5–2c3))/6
7 8
Short-Job-First Scheduling Scheduling Policies
Estimating execution time Priority Scheduling (PS)

Jobs are enqueued in order of estimated completion time Assign a priority (a number) to each job and schedule jobs in
ÿ “Recent history is a good indicator of the near future” order of priority
ÿ Typically low priority values = “high priority”
E.g., if priority = tn, then a priority scheduler becomes a SJF
process PP
process scheduler.
begin
begin
loop
loop
<read
<readinput
inputfrom
fromuser>
user>
<process
<processinput>
input>
end
end loop
loop Px Pc Pb Pa CPU
CPU
end PP
end

Low High
t n — duration of the nth CPU burst Priority Priority
tn+1 — predicted duration of the n+1 st CPU burst (large (small
number) number)
tn+1 = atn + (1– a)tn, for 0 ≤ a ≤ 1

9 10

Priority Scheduling
Avoiding starvation Non Pre-emptive vs. Pre-emptive Scheduling

Aging Non Pre-emptive Scheduling:


ÿ Gradually increase a process’s priority (decrease its priority value) ÿ Once a process begins execution, it occupies CPU until it
over time finishes or it blocks
ÿ Advantage: simplicity, but …
ÿ Creates problems … (like what?)
Priority
ÿ Examples: FCFS, SJF, PS, …

Pre-emptive Scheduling:
Time ÿ A process is switched back and forth between running and
ready states
ÿ Advantage: more efficient, better capabilities, but …
ÿ More complex and needs hardware support (e.g., timer
Px Pc Pb Pa CPU interrupts)
CPU
ÿ Examples: Round Robin, Shortest Remaining Time First (SRTF),
Multi-level Feedback Queue (MLF)
11 12
Scheduling Policies
Round-Robin Scheduling (RR) RR Scheduling: Selecting a Time Quantum

Allocate the processor in discrete unit called quanta (or time- Too large
slices)
ÿ Long waiting time
ÿ Degenerates to FCFS in the limit
Switch to the next ready process at the end of each quantum
ÿ Processes execute every (n – 1) q time units
Too small
ÿ Responsive, but …
Process ÿ Throughput suffers due to large context switch overhead
<q Completion
Px Pc Pb Pa CPU
CPU or
I/O Request
Goal:
=q
ÿ Select a time quantum that balances this tradeoff
Timer Interrupt ÿ Rule of thumb: maintain context switch overhead to less
than 1%

13 14

Scheduling Policies
Multi-level feedback queues (MLF)

n priority levels — priority scheduling between levels, round-


robin within a level

Quantum size decreases with priority level

Jobs are demoted to lower priority levels if they don’t


complete within the current quantum
Level 1
q = t0
High
Priority Pa

Level 2
q = 2t0
P3 P2 P1
CPU
CPU
...

...

Level n
Low
Priority Py Px q = 2 n-1 t
0
15

Common questions

Powered by AI

SJF minimizes response time by selecting the shortest jobs first, ensuring that small jobs are completed quickly. This method requires clairvoyance or user input to estimate job lengths, which makes it difficult to implement accurately. A significant drawback of SJF is the potential for starvation, where continuous short jobs can indefinitely delay longer processes from executing .

In Round Robin scheduling, the quantum is the fixed time period allotted for each process to execute before switching to the next. Selecting the right quantum size critically affects system performance; a larger quantum may lead to longer waiting times and reduced system responsiveness, nearing First-Come-First-Served behavior, while a smaller quantum enhances responsiveness but can increase context-switching overhead, reducing throughput. Therefore, a balanced quantum ensures responsiveness without compromising efficiency, typically by ensuring context switch overhead stays below 1% .

MLF uses multiple priority levels for processes, applying round-robin scheduling within each level but allowing quantum sizes to decrease with priority level. This strategy adapts to varying process requirements and demotes jobs to lower priority levels if they don't complete within the designated quantum. The main advantage of MLF is its flexibility in providing dynamic adjustments to process scheduling, balancing between responsiveness and throughput .

Preemptive scheduling optimizes process management by allowing the CPU to switch between processes in response to external events, reducing idle time and enhancing responsiveness. It supports efficient time-sharing systems and multitasking. However, this approach introduces challenges such as increased complexity in process management, requiring sophisticated algorithms and hardware features like timer interrupts, which can complicate system design and increase overhead .

Non-preemptive scheduling allows a process to occupy the CPU until it finishes or blocks, offering simplicity but leading to potential issues like long waiting times for other processes. Examples include First-Come-First-Served (FCFS), Shortest Job First (SJF), and Priority Scheduling (PS). Preemptive scheduling involves switching processes between running and ready states, which allows for better efficiency and capabilities but requires more complex mechanisms and hardware support such as timer interrupts. Examples include Round Robin (RR), Shortest Remaining Time First (SRTF), and Multi-level Feedback Queue (MLF).

Process state transitions occur between the states of Ready, Running, and Waiting. Transitions are triggered by specific conditions: a process moves from running to waiting due to its action, non-preemptive scheduling; from running to ready due to external events, preemptive scheduling; from waiting to ready once resources are available; and finally, from running to terminated when the process completes its execution .

The scheduling discipline significantly affects CPU and device utilization, influencing overall system efficiency. Disciplines like FCFS can lead to poor overlap of I/O and CPU processing, causing devices to remain idle while CPU-bound processes execute. Performance metrics commonly used to assess scheduling include CPU/device utilization rates, system throughput, waiting time, and response time, each reflecting different aspects of scheduler efficiency and system performance .

Estimating execution time is crucial in SJF scheduling because it determines job ordering to minimize response time. An effective method for estimation is using historical data, where the predicted length of the next CPU burst is calculated using prior burst durations. The formula tn+1 = αtn + (1–α)tn for 0 ≤ α ≤ 1 leverages the principle that recent history can indicate near-future performance .

Round Robin scheduling assigns each process a fixed time quantum within which it can run, after which the next ready process is scheduled. Selecting a time quantum involves trade-offs: a large quantum increases waiting time and can resemble FCFS, whereas a small quantum improves responsiveness but decreases throughput due to increased context switch overhead. The goal is to balance these factors to keep context switch overhead below 1% .

Aging is a technique used in Priority Scheduling systems to prevent starvation by gradually increasing a process's priority over time. This is done by decreasing the numerical priority value, which eventually makes lower-priority processes more competitive and ensures they eventually receive CPU time, thus enhancing fairness in the scheduling system .

You might also like