Module OLASO
Module OLASO
Module
Submitted to the Faculty of
Department of Information Technology
Cavite State University General Trias City Campus
General Trias City, Cavite
In Partial Fulfillment
Of the requirements for the degree
Bachelor of Science in Information Technology
Burst Time: It is a time required by the process to complete execution. It is also called running
time.
Process: It is the reference that is used for both job and user.
Completion Time: When a process finishes execution and is no longer being processed by the
CPU.
Waiting Time: the total time a process takes while waiting in a ready queue before reaching
the CPU.
1
Types of CPU Scheduling
CPU Scheduling
PRE-EMPTIVE NON-PRE-EMPTIVE
Preemptive Scheduling
In Preemptive Scheduling, the tasks are mostly assigned with their priorities. Sometimes it is
important to run a task with a higher priority before another lower priority task, even if the lower
priority task is still running. The lower priority task holds for some time and resumes when the
higher priority task finishes its execution.
Non-Preemptive Scheduling
In this type of scheduling method, the CPU has been allocated to a specific process. The
process that keeps the CPU busy will release the CPU either by switching context or
terminating. It is the only method that can be used for various hardware platforms. That’s
because it doesn’t need special hardware (for example, a timer) like preemptive scheduling.
2
CPU scheduling algorithm. In this type of algorithm, processes which requests the CPU
first get the CPU allocation first. This is managed with a FIFO queue. The full form of
FCFS is First Come First Serve.
3
Process Burst time Arrival time
P3 8 1
P4 3 0
P5 4 4
P1 6 2
P2 2 5
4
Process Burst time Arrival time
P3 8 1
P4 3 0
P5 4 4
Step 8) At time=11, P1 starts execution. It has a burst time of 6. It completes execution at time
interval 17
5
Step 10) At time=21, P2 starts execution. It has a burst time of 2. It completes execution at time
interval 23
Step 11) Let’s calculate the average waiting time for above example.
P3 = 3-1 = 2
PI = 11-2 = 9
P5= 17-4 = 13
P2= 21-5= 16
0+2+9+13+16
= 40/5= 8 ms
6
Shortest Job First (SJF)
-It is an algorithm in which the process having the smallest execution time is chosen for
the next execution. This scheduling method can be preemptive or non-preemptive. It
significantly reduces the average waiting time for other processes awaiting execution. The full
form of SJF is Shortest Job First.
Non-Preemptive SJF
Preemptive SJF
Non-Preemptive SJF
In non-preemptive scheduling, once the CPU cycle is allocated to process, the process holds it
till it reaches a waiting state or terminated.
Consider the following five processes each having its own unique burst time and arrival time.
Step 1) At time= 1, Process P3 arrives. But, P4 still needs 2 execution units to complete. It will
continue execution.
7
Step 2) At time =2, process P1 arrives and is added to the waiting queue. P4 will continue
execution.
Step 3) At time = 3, process P4 will finish its execution. The burst time of P3 and P1 is
compared. Process P1 is executed because its burst time is less compared to P3.
Step 4) At time = 4, process P5 arrives and is added to the waiting queue. P1 will continue
execution.
Step 5) At time = 5, process P2 arrives and is added to the waiting queue. P1 will continue
execution.
Step 6) At time = 9, process P1 will finish its execution. The burst time of P3, P5, and P2 is
compared. Process P2 is executed because its burst time is the lowest.
8
Step 7) At time=10, P2 is executing and P3 and P5 are in the waiting queue.
Step 8) At time = 11, process P2 will finish its execution. The burst time of P3 and P5 is
compared. Process P5 is executed because its burst time is lower.
9
Step 11) Let’s calculate the average waiting time for above example.
Wait time
P4= 0-0=0
P1= 3-2=1
P2= 9-5=4
P5= 11-4=7
P3= 15-1=14
Average Waiting Time= 0+1+4+7+14/5 = 26/5 = 5.2ms
Preemptive SJF
In Preemptive SJF Scheduling, jobs are put into the ready queue as they come. A process with
shortest burst time begins execution. If a process with even a shorter burst time arrives, the
current process is removed or preempted from execution, and the shorter job is allocated CPU
cycle.
10
Step 1) At time= 1, Process P3 arrives. But, P4 has a shorter burst time. It will continue
execution.
Step 2) At time = 2, process P1 arrives with burst time = 6. The burst time is more than that of
P4. Hence, P4 will continue execution.
Step 3) At time = 3, process P4 will finish its execution. The burst time of P3 and P1 is
compared. Process P1 is executed because its burst time is lower.
Step 4) At time = 4, process P5 will arrive. The burst time of P3, P5, and P1 is compared.
Process P5 is executed because its burst time is lowest. Process P1 is preempted.
11
Process Queue Burst time Arrival time
P1 5 out of 6 is remaining 2
P2 2 5
P3 8 1
P4 3 0
P5 4 4
Step 5) At time = 5, process P2 will arrive. The burst time of P1, P2, P3, and P5 is compared.
Process P2 is executed because its burst time is least. Process P5 is preempted.
Step 7) At time =7, P2 finishes its execution. The burst time of P1, P3, and P5 is compared.
Process P5 is executed because its burst time is lesser.
12
Process Queue Burst time Arrival time
P1 5 out of 6 is remaining 2
P2 2 5
P3 8 1
P4 3 0
P5 3 out of 4 is remaining 4
Step 8) At time =10, P5 will finish its execution. The burst time of P1 and P3 is compared.
Process P1 is executed because its burst time is less.
Step 9) At time =15, P1 finishes its execution. P3 is the only process left. It will start execution.
13
Step 11) Let’s calculate the average waiting time for above example.
Wait time
P4= 0-0=0
P1= (3-2) + 6 =7
P2= 5-5 = 0
P5= 4-4+2 =2
P3= 15-1 = 14
Average Waiting Time = 0+7+0+2+14/5 = 23/5 =4.6
14
Priority Scheduling
-It is a process scheduling algorithm based on priority where the scheduler selects tasks
according to priority. Thus, processes with higher priorities are executed first followed by
processes with lower priorities.
If two jobs have the same priorities, then the process that should be executed first is chosen on
the basis of round-robin or FCFS. Which process should have priority depends on a process’
memory requirements, time requirements, the ratio of I/O burst to CPU burst etc.
1. Preemptive Priority Scheduling: If the new process arrived at the ready queue has a
higher priority than the currently running process, the CPU is preempted, which means
the processing of the current process is stopped and the incoming new process with
higher priority gets the CPU for its execution.
P1 0 4 2
P2 1 3 3
P3 2 1 4
P4 3 5 5
P5 4 2 5
15
P1 P4 P5 P3 P2
Gantt Chart:
0 4 9 11 12 15
Now, we know-
Turn Around time = Completion time – Arrival time
Waiting time = Turn Around time – Burst time
P1 4 4–0=4 4–4=0
P2 15 15 – 1 = 14 14 – 3 = 11
P3 12 12 – 2 = 10 10 – 1 = 9
P4 9 9–3=6 6–5=1
P5 11 11 – 4 = 7 7–2=5
16
Round-robin (RR)
-It is one of the algorithms employed by process and network schedulers in
computing.As the term is generally used, time slices are assigned to each process in equal
portions and in circular order, handling all processes without priority. Round-robin scheduling is
simple, easy to implement, and starvation-free. Round-robin scheduling can be applied to other
scheduling problems, such as data packet scheduling in computer networks. It is an operating
system concept. The Round robin scheduling is one of the CPU scheduling in which every
process gets a fixed amount of time quantum to execute the process. In this scheduling, every
process gets executed cyclically. This means that processes that have their burst time
remaining after the expiration of the time quantum are sent back to the ready state and wait for
their next turn to complete the execution until it terminates. This processing is done in FIFO
order which suggests that processes are executed on a first-come, first-serve basis.
In Round-Robin Scheduling,
CPU is assigned to the process based on FCFS for a fixed amount of time.
This fixed amount of time is called as time quantum or time slice.
After the time quantum expires, the running process is preempted and sent to the ready
queue.
Then, the processor is assigned to the next arrived process.
It is always preemptive in nature.
P1 0 5
P2 1 3
P3 2 1
P4 3 2
P5 4 3
17
Gantt Chart:
P1 P2 P3 P1 P4 P5 P2 P1 P5
0 2 4 5 7 9 11 12 13 14
Now, we know-
Turn Around time = Completion Time– Arrival time
Waiting time = Turn Around time – Burst time
Completion
Process Id Turn Around time Waiting time
time
P1 13 13 – 0 = 13 13 – 5 = 8
P2 12 12 – 1 = 11 11 – 3 = 8
P3 5 5–2=3 3–1=2
P4 9 9–3=6 6–2=4
P5 14 14 – 4 = 10 10 – 3 = 7
Now,
Average Turn Around time = (13 + 11 + 3 + 6 + 10) / 5 = 43 / 5 = 8.6 ms
Average waiting time = (8 + 8 + 2 + 4 + 7) / 5 = 29 / 5 = 5.8 ms
18
The Purpose of CPU Scheduling
The primary objective of CPU scheduling is to ensure that as many jobs are running at a
time as is possible. On a single-CPU system the goal is to keep one job always running.
19
REFERENCES
https://www.geeksforgeeks.org/cpu-scheduling-criteria/?
fbclid=IwAR2uiiHt5_2Loe9J0HhHHHEP-Fz5DxI4P1Ysj3RqR6VuuRB4QxhAxddo02M
https://www.guru99.com/cpu-scheduling-algorithms.html?fbclid=IwAR0G_4baq-
1xpGYPtMDt65-CjvWE-yQ53PFyuV22OyWfXNO3uTrFtzy8fQI
FCFS Scheduling Algorithm: What is, Example Program. (2024, February 3). Guru99.
https://www.guru99.com/fcfs-scheduling.html?fbclid=IwAR3bYhYMs6mWBNLDOb7-
5VMq9jkMYvskgiAr4oG26pIa4FQBEjnIURDBzHM
Shortest Job First (SJF): Preemptive, Non-Preemptive Example. (2024, February 3). Guru99.
https://www.guru99.com/shortest-job-first-sjf-scheduling.html?fbclid=IwAR2RTJJ1lV-
83p9yBj2qLPcHJgEeopwQwHJXJzdWIRTf4MyN0CaafBq0vKg
scheduling-examples/?
fbclid=IwAR2OZkdGvotRt7DBQX7vVyZqC35_TBeuM2T4gyM91AA8CbMKaLuafiQn
exA
Sharma, V. (2022, August 29). What is Round Robin Scheduling in OS? - Scaler Topics. Scaler
fbclid=IwAR0nbf2ciJoia6jq9mLCUPnUeew5fM6-6aLgX8LCg1KwaZb24cc-SwgwvJ0
scheduling-examples/?
fbclid=IwAR0CpVvge3NOKosYF5J0wKhlD1WioGX4PEKTifwjDFpTOlaOiQMtuz0OR
zQ
20