CPU scheduling is the process by which the CPU selects which process to execute next from among processes in memory that are ready to execute. The CPU scheduler selects processes from the ready queue to execute. The goal of CPU scheduling is to maximize CPU utilization and throughput while minimizing waiting time and response time. Common CPU scheduling algorithms include first come first serve (FCF) which services processes in the order they arrive, and shortest job first (SJF) which selects the process with the shortest estimated run time to execute next.
The document discusses operating system scheduling. It defines key scheduling criteria like CPU utilization, throughput, turnaround time, waiting time, and response time. It also outlines common scheduling algorithms like first-come first-served (FCFS), shortest-job-next (SJN), priority scheduling, shortest remaining time, and round robin. For each algorithm, it provides examples of how they work and how to calculate metrics like waiting time and turnaround time. It also distinguishes between time-sharing systems, which context switch between processes frequently for fast response, and parallel processing systems, which divide programs across multiple processors.
Task scheduling is needed to maintain every process that comes with a processor in parallel processing. In several conditions, not every algorithm works better on the significant problem. Sometimes FCFS algorithm is better than the other in short burst time while Round Robin is better for multiple processes in every single time. But we cannot predict what process will come after. Average Waiting Time is a standard measure for giving credit to the scheduling algorithm. Several techniques have been applied to maintain the process in order to make the CPU performance in normal. The objective of this paper is to compare three algorithms, FCFS, SJF and Round Robin. Finally, we know which algorithm is more suitable for the certain process.
1. Process management is an integral part of operating systems for allocating resources, enabling information sharing, and protecting processes. The OS maintains data structures describing each process's state and resource ownership.
2. Processes go through discrete states and events can cause state changes. Scheduling selects processes to run from ready, device, and job queues using algorithms like round robin, shortest job first, and priority scheduling.
3. CPU scheduling aims to maximize utilization and throughput while minimizing waiting times using criteria like response time, turnaround time, and fairness between processes.
Operating Systems Third Unit - Fourth Semester - EngineeringYogesh Santhan
The document describes CPU scheduling concepts in a multiprogramming operating system. It discusses how CPU scheduling depends on CPU bursts and I/O waits as processes alternate between the two states. The scheduler selects processes from the ready queue to run on the CPU. Scheduling can be preemptive, occurring when a process changes states, or non-preemptive. Common scheduling algorithms like first-come, first-served, shortest job first, priority, and round robin are described. Optimization criteria for scheduling like CPU utilization, throughput, turnaround time and waiting time are also covered.
Priority scheduling assigns priorities to processes and executes the highest priority process first. If processes have equal priorities, they are executed in first come first served order. The example document shows how priority scheduling works by assigning priorities from 1 to 5 to five processes, then calculating their waiting times and turnaround times based on executing the highest priority processes first. Round robin scheduling assigns a fixed time quantum to each process, preempting and resuming processes to ensure all get CPU time and avoid starvation. The example shows how time is divided between processes using a 2ms time quantum.
CPU scheduling decides which processes run when multiple are ready. It aims to make the system efficient, fast and fair. There are different scheduling algorithms like first come first serve (FCFS), shortest job first (SJF), priority scheduling, and round robin. Multi-level feedback queue scheduling uses multiple queues and allows processes to move between queues based on their CPU usage to prioritize shorter interactive processes.
The document discusses various CPU scheduling concepts and algorithms. It covers basic concepts like CPU-I/O burst cycles and scheduling criteria. It then describes common scheduling algorithms like first come first served (FCFS), shortest job first (SJF), priority scheduling, and round robin (RR). It also discusses more advanced topics like multi-level queue scheduling, multi-processor scheduling, and thread scheduling in Linux.
CPU scheduling is the process by which the CPU selects which process to execute next from among processes in memory that are ready to execute. The CPU scheduler selects processes from the ready queue to execute. The goal of CPU scheduling is to maximize CPU utilization and throughput while minimizing waiting time and response time. Common CPU scheduling algorithms include first come first serve (FCF) which services processes in the order they arrive, and shortest job first (SJF) which selects the process with the shortest estimated run time to execute next.
The document discusses operating system scheduling. It defines key scheduling criteria like CPU utilization, throughput, turnaround time, waiting time, and response time. It also outlines common scheduling algorithms like first-come first-served (FCFS), shortest-job-next (SJN), priority scheduling, shortest remaining time, and round robin. For each algorithm, it provides examples of how they work and how to calculate metrics like waiting time and turnaround time. It also distinguishes between time-sharing systems, which context switch between processes frequently for fast response, and parallel processing systems, which divide programs across multiple processors.
Task scheduling is needed to maintain every process that comes with a processor in parallel processing. In several conditions, not every algorithm works better on the significant problem. Sometimes FCFS algorithm is better than the other in short burst time while Round Robin is better for multiple processes in every single time. But we cannot predict what process will come after. Average Waiting Time is a standard measure for giving credit to the scheduling algorithm. Several techniques have been applied to maintain the process in order to make the CPU performance in normal. The objective of this paper is to compare three algorithms, FCFS, SJF and Round Robin. Finally, we know which algorithm is more suitable for the certain process.
1. Process management is an integral part of operating systems for allocating resources, enabling information sharing, and protecting processes. The OS maintains data structures describing each process's state and resource ownership.
2. Processes go through discrete states and events can cause state changes. Scheduling selects processes to run from ready, device, and job queues using algorithms like round robin, shortest job first, and priority scheduling.
3. CPU scheduling aims to maximize utilization and throughput while minimizing waiting times using criteria like response time, turnaround time, and fairness between processes.
Operating Systems Third Unit - Fourth Semester - EngineeringYogesh Santhan
The document describes CPU scheduling concepts in a multiprogramming operating system. It discusses how CPU scheduling depends on CPU bursts and I/O waits as processes alternate between the two states. The scheduler selects processes from the ready queue to run on the CPU. Scheduling can be preemptive, occurring when a process changes states, or non-preemptive. Common scheduling algorithms like first-come, first-served, shortest job first, priority, and round robin are described. Optimization criteria for scheduling like CPU utilization, throughput, turnaround time and waiting time are also covered.
Priority scheduling assigns priorities to processes and executes the highest priority process first. If processes have equal priorities, they are executed in first come first served order. The example document shows how priority scheduling works by assigning priorities from 1 to 5 to five processes, then calculating their waiting times and turnaround times based on executing the highest priority processes first. Round robin scheduling assigns a fixed time quantum to each process, preempting and resuming processes to ensure all get CPU time and avoid starvation. The example shows how time is divided between processes using a 2ms time quantum.
CPU scheduling decides which processes run when multiple are ready. It aims to make the system efficient, fast and fair. There are different scheduling algorithms like first come first serve (FCFS), shortest job first (SJF), priority scheduling, and round robin. Multi-level feedback queue scheduling uses multiple queues and allows processes to move between queues based on their CPU usage to prioritize shorter interactive processes.
The document discusses various CPU scheduling concepts and algorithms. It covers basic concepts like CPU-I/O burst cycles and scheduling criteria. It then describes common scheduling algorithms like first come first served (FCFS), shortest job first (SJF), priority scheduling, and round robin (RR). It also discusses more advanced topics like multi-level queue scheduling, multi-processor scheduling, and thread scheduling in Linux.
This document describes an experiment to implement and compare two CPU scheduling algorithms: shortest job first (SJF) and round robin. It provides background on SJF and round robin scheduling, including their advantages and disadvantages. Formulas to calculate completion time, turnaround time, and waiting time are provided for analyzing SJF scheduling. Pseudocode is included for algorithms to implement SJF and round robin scheduling. The objective is to demonstrate and program these two algorithms with different process arrival times.
The document discusses various CPU scheduling algorithms used in operating systems. It describes the main objective of CPU scheduling as maximizing CPU utilization by allowing multiple processes to share the CPU. It then explains different scheduling criteria like throughput, turnaround time, waiting time and response time. Finally, it summarizes common scheduling algorithms like first come first served, shortest job first, priority scheduling and round robin scheduling.
This document discusses various CPU scheduling algorithms and concepts. It covers scheduling criteria like CPU utilization and turnaround time. Algorithms discussed include first-come first-served (FCFS), shortest job first (SJF), priority scheduling, and round robin (RR). It also covers multiple queue scheduling, real-time scheduling, and ways to evaluate scheduling algorithm performance like deterministic modeling and simulation.
The document discusses several topics related to CPU scheduling, including basic concepts, scheduling criteria, algorithms like first-come first-served (FCFS) and shortest-job-first (SJF), determining CPU burst lengths, priority scheduling, and approaches to scheduling on multiple processors. Key concepts are that the CPU scheduler selects ready processes to run and aims to maximize CPU utilization while minimizing waiting times using algorithms like FCFS, SJF, priority, and round robin scheduling. Load sharing and affinity are considerations for multiprocessor scheduling.
This document discusses various CPU scheduling algorithms and concepts. It covers scheduling criteria like CPU utilization and turnaround time. Algorithms discussed include first-come first-served (FCFS), shortest job first (SJF), priority scheduling, and round robin (RR). It also covers multiple processor scheduling, real-time scheduling, and evaluating scheduling algorithms.
This document discusses various CPU scheduling algorithms and concepts. It covers scheduling criteria like CPU utilization and turnaround time. Algorithms discussed include first-come first-served (FCFS), shortest job first (SJF), priority scheduling, and round robin (RR). It also covers multiple processor scheduling, real-time scheduling, and evaluating scheduling algorithms.
This Presention contains Cpu scheduling algorithms,Scheduling Criteria,process sychroization,mutilevel feed back que,critical section problem anad semaphores,Synchoroniztion hardware
This document discusses various CPU scheduling algorithms. It provides details on First Come First Serve (FCFS), Shortest Job First (SJF), Priority Scheduling, Round Robin Scheduling, and Multi-Level Queue Scheduling. Examples are given to illustrate how each algorithm works. The key points covered include how each algorithm determines which process gets CPU time, whether they are preemptive or not, and how to calculate waiting times.
The document discusses various CPU scheduling algorithms including First-Come-First-Served (FCFS), Shortest Job First (SJF), Priority Scheduling, Round Robin Scheduling, and examples of how each works. It provides details on how each algorithm prioritizes and schedules processes waiting in the ready queue for CPU allocation. Examples are given to illustrate the average waiting times that can result from different scheduling approaches.
The document discusses various scheduling algorithms used in operating systems including:
- First Come First Serve (FCFS) scheduling which services processes in the order they arrive but can lead to long wait times.
- Shortest Job First (SJF) scheduling which prioritizes the shortest processes first to minimize wait times. This can be preemptive or non-preemptive.
- Priority scheduling which assigns priorities to processes and services the highest priority first, which can cause starvation of low priority processes.
- Round Robin scheduling which allows fair sharing of the CPU by allocating a time quantum or slice to each process in a cyclic manner.
The document discusses various scheduling algorithms used in operating systems including:
- First Come First Serve (FCFS) scheduling which services processes in the order of arrival but can lead to long waiting times.
- Shortest Job First (SJF) scheduling which prioritizes the shortest processes first to minimize waiting times. It can be preemptive or non-preemptive.
- Priority scheduling assigns priorities to processes and services the highest priority process first, which can potentially cause starvation of low priority processes.
- Round Robin scheduling allows equal CPU access to all processes by allowing each a small time quantum before being preempted. It has lower average waiting times than FCFS but higher than SJF.
The document discusses various scheduling algorithms used in operating systems including:
- First Come First Serve (FCFS) scheduling which services processes in the order of arrival but can lead to long waiting times.
- Shortest Job First (SJF) scheduling which prioritizes the shortest processes first to minimize waiting times. It can be preemptive or non-preemptive.
- Priority scheduling assigns priorities to processes and services the highest priority process first, which can potentially cause starvation of low priority processes.
- Round Robin scheduling allows equal CPU access to all processes by allowing each a small time quantum or slice before preempting to the next process.
The Longest Remaining Time First (LRTF) scheduling algorithm schedules the process with the longest remaining burst time first. It works by first scheduling the process with the earliest arrival time. Then, it schedules either the next arriving process or the current process depending on which has the longer remaining burst time. This continues until all processes have been executed. While simple to implement, LRTF can result in higher average waiting times and turnaround times compared to the Shortest Remaining Time First algorithm.
The document discusses process scheduling in operating systems. It covers basic concepts like scheduling criteria, algorithms like FCFS, SJF, priority and round robin scheduling. It explains key process states and scheduling techniques like preemptive and non-preemptive. Examples are provided to illustrate different scheduling algorithms and how they optimize criteria like waiting time, response time and CPU utilization.
Here are the steps to solve this problem:
a) Non-Preemptive Priority Scheduling:
- Process order based on priority: P2, P4, P1, P3
- Number of context switches = 3
b) Round Robin Scheduling with time slice = 2:
- Process order: P1, P2, P1, P4, P1, P3, P1
- Number of context switches = 6
c) With RR, the behavior depends on the time slice size. With a small time slice of 2ms, most processes cannot complete within one time slice. This leads to a larger number of context switches compared to priority scheduling.
d)
This document discusses CPU scheduling in operating systems. It begins by introducing CPU scheduling and describing the goals of scheduling algorithms. It then explains common scheduling algorithms like first-come first-served (FCFS), shortest job first (SJF), priority scheduling, and round robin (RR). The document also covers multilevel queue scheduling, thread scheduling, multiple processor scheduling, and real-time CPU scheduling.
CPU scheduling allows processes to share the CPU by pausing one process to run another that is waiting. Scheduling occurs when a process changes state from running to waiting or ready, or when a process terminates. Scheduling can be non-preemptive, only occurring during state changes 1 and 4, or preemptive when any state change triggers scheduling. Common scheduling algorithms include first-come, first-served (FCFS), shortest job first (SJF), priority, and round robin. FCFS considers processes in the order they arrive but can result in long wait times if earlier processes have long bursts.
* Using SJF preemptive scheduling:
P2 will execute from time 0 to 5 ms.
P3 will execute from time 5 to 8 ms.
P1 will execute from time 8 to 18 ms.
P4 will execute from time 18 to 38 ms.
P5 will execute from time 38 to 40 ms.
Total waiting time = (10-5) + (8-5) + (18-0) + (38-5) + (40-10) = 5.6 + 3 + 18 + 33 + 30 = 90
Average waiting time = Total waiting time / Number of processes = 90/5 = 5.6 ms
* Using Priority preemptive scheduling
The document discusses different CPU scheduling algorithms:
1. First Come First Served scheduling allocates CPU to the longest waiting process first, which can result in longer processes waiting behind shorter ones (convoy effect).
2. Shortest Job First scheduling allocates CPU to the process with the shortest estimated run time, minimizing average wait time. Preemptive SJF allows interrupting the current process if a shorter one arrives.
3. Priority scheduling assigns priority levels and allocates CPU to the highest priority ready process. Preemption and aging policies address starvation of lower priority processes.
4. Round Robin scheduling allocates a time quantum (e.g. 10-100ms) to each ready process
Embedded machine learning-based road conditions and driving behavior monitoringIJECEIAES
Car accident rates have increased in recent years, resulting in losses in human lives, properties, and other financial costs. An embedded machine learning-based system is developed to address this critical issue. The system can monitor road conditions, detect driving patterns, and identify aggressive driving behaviors. The system is based on neural networks trained on a comprehensive dataset of driving events, driving styles, and road conditions. The system effectively detects potential risks and helps mitigate the frequency and impact of accidents. The primary goal is to ensure the safety of drivers and vehicles. Collecting data involved gathering information on three key road events: normal street and normal drive, speed bumps, circular yellow speed bumps, and three aggressive driving actions: sudden start, sudden stop, and sudden entry. The gathered data is processed and analyzed using a machine learning system designed for limited power and memory devices. The developed system resulted in 91.9% accuracy, 93.6% precision, and 92% recall. The achieved inference time on an Arduino Nano 33 BLE Sense with a 32-bit CPU running at 64 MHz is 34 ms and requires 2.6 kB peak RAM and 139.9 kB program flash memory, making it suitable for resource-constrained embedded systems.
More Related Content
Similar to Program for FCFS CPU Scheduling.program docx
This document describes an experiment to implement and compare two CPU scheduling algorithms: shortest job first (SJF) and round robin. It provides background on SJF and round robin scheduling, including their advantages and disadvantages. Formulas to calculate completion time, turnaround time, and waiting time are provided for analyzing SJF scheduling. Pseudocode is included for algorithms to implement SJF and round robin scheduling. The objective is to demonstrate and program these two algorithms with different process arrival times.
The document discusses various CPU scheduling algorithms used in operating systems. It describes the main objective of CPU scheduling as maximizing CPU utilization by allowing multiple processes to share the CPU. It then explains different scheduling criteria like throughput, turnaround time, waiting time and response time. Finally, it summarizes common scheduling algorithms like first come first served, shortest job first, priority scheduling and round robin scheduling.
This document discusses various CPU scheduling algorithms and concepts. It covers scheduling criteria like CPU utilization and turnaround time. Algorithms discussed include first-come first-served (FCFS), shortest job first (SJF), priority scheduling, and round robin (RR). It also covers multiple queue scheduling, real-time scheduling, and ways to evaluate scheduling algorithm performance like deterministic modeling and simulation.
The document discusses several topics related to CPU scheduling, including basic concepts, scheduling criteria, algorithms like first-come first-served (FCFS) and shortest-job-first (SJF), determining CPU burst lengths, priority scheduling, and approaches to scheduling on multiple processors. Key concepts are that the CPU scheduler selects ready processes to run and aims to maximize CPU utilization while minimizing waiting times using algorithms like FCFS, SJF, priority, and round robin scheduling. Load sharing and affinity are considerations for multiprocessor scheduling.
This document discusses various CPU scheduling algorithms and concepts. It covers scheduling criteria like CPU utilization and turnaround time. Algorithms discussed include first-come first-served (FCFS), shortest job first (SJF), priority scheduling, and round robin (RR). It also covers multiple processor scheduling, real-time scheduling, and evaluating scheduling algorithms.
This document discusses various CPU scheduling algorithms and concepts. It covers scheduling criteria like CPU utilization and turnaround time. Algorithms discussed include first-come first-served (FCFS), shortest job first (SJF), priority scheduling, and round robin (RR). It also covers multiple processor scheduling, real-time scheduling, and evaluating scheduling algorithms.
This Presention contains Cpu scheduling algorithms,Scheduling Criteria,process sychroization,mutilevel feed back que,critical section problem anad semaphores,Synchoroniztion hardware
This document discusses various CPU scheduling algorithms. It provides details on First Come First Serve (FCFS), Shortest Job First (SJF), Priority Scheduling, Round Robin Scheduling, and Multi-Level Queue Scheduling. Examples are given to illustrate how each algorithm works. The key points covered include how each algorithm determines which process gets CPU time, whether they are preemptive or not, and how to calculate waiting times.
The document discusses various CPU scheduling algorithms including First-Come-First-Served (FCFS), Shortest Job First (SJF), Priority Scheduling, Round Robin Scheduling, and examples of how each works. It provides details on how each algorithm prioritizes and schedules processes waiting in the ready queue for CPU allocation. Examples are given to illustrate the average waiting times that can result from different scheduling approaches.
The document discusses various scheduling algorithms used in operating systems including:
- First Come First Serve (FCFS) scheduling which services processes in the order they arrive but can lead to long wait times.
- Shortest Job First (SJF) scheduling which prioritizes the shortest processes first to minimize wait times. This can be preemptive or non-preemptive.
- Priority scheduling which assigns priorities to processes and services the highest priority first, which can cause starvation of low priority processes.
- Round Robin scheduling which allows fair sharing of the CPU by allocating a time quantum or slice to each process in a cyclic manner.
The document discusses various scheduling algorithms used in operating systems including:
- First Come First Serve (FCFS) scheduling which services processes in the order of arrival but can lead to long waiting times.
- Shortest Job First (SJF) scheduling which prioritizes the shortest processes first to minimize waiting times. It can be preemptive or non-preemptive.
- Priority scheduling assigns priorities to processes and services the highest priority process first, which can potentially cause starvation of low priority processes.
- Round Robin scheduling allows equal CPU access to all processes by allowing each a small time quantum before being preempted. It has lower average waiting times than FCFS but higher than SJF.
The document discusses various scheduling algorithms used in operating systems including:
- First Come First Serve (FCFS) scheduling which services processes in the order of arrival but can lead to long waiting times.
- Shortest Job First (SJF) scheduling which prioritizes the shortest processes first to minimize waiting times. It can be preemptive or non-preemptive.
- Priority scheduling assigns priorities to processes and services the highest priority process first, which can potentially cause starvation of low priority processes.
- Round Robin scheduling allows equal CPU access to all processes by allowing each a small time quantum or slice before preempting to the next process.
The Longest Remaining Time First (LRTF) scheduling algorithm schedules the process with the longest remaining burst time first. It works by first scheduling the process with the earliest arrival time. Then, it schedules either the next arriving process or the current process depending on which has the longer remaining burst time. This continues until all processes have been executed. While simple to implement, LRTF can result in higher average waiting times and turnaround times compared to the Shortest Remaining Time First algorithm.
The document discusses process scheduling in operating systems. It covers basic concepts like scheduling criteria, algorithms like FCFS, SJF, priority and round robin scheduling. It explains key process states and scheduling techniques like preemptive and non-preemptive. Examples are provided to illustrate different scheduling algorithms and how they optimize criteria like waiting time, response time and CPU utilization.
Here are the steps to solve this problem:
a) Non-Preemptive Priority Scheduling:
- Process order based on priority: P2, P4, P1, P3
- Number of context switches = 3
b) Round Robin Scheduling with time slice = 2:
- Process order: P1, P2, P1, P4, P1, P3, P1
- Number of context switches = 6
c) With RR, the behavior depends on the time slice size. With a small time slice of 2ms, most processes cannot complete within one time slice. This leads to a larger number of context switches compared to priority scheduling.
d)
This document discusses CPU scheduling in operating systems. It begins by introducing CPU scheduling and describing the goals of scheduling algorithms. It then explains common scheduling algorithms like first-come first-served (FCFS), shortest job first (SJF), priority scheduling, and round robin (RR). The document also covers multilevel queue scheduling, thread scheduling, multiple processor scheduling, and real-time CPU scheduling.
CPU scheduling allows processes to share the CPU by pausing one process to run another that is waiting. Scheduling occurs when a process changes state from running to waiting or ready, or when a process terminates. Scheduling can be non-preemptive, only occurring during state changes 1 and 4, or preemptive when any state change triggers scheduling. Common scheduling algorithms include first-come, first-served (FCFS), shortest job first (SJF), priority, and round robin. FCFS considers processes in the order they arrive but can result in long wait times if earlier processes have long bursts.
* Using SJF preemptive scheduling:
P2 will execute from time 0 to 5 ms.
P3 will execute from time 5 to 8 ms.
P1 will execute from time 8 to 18 ms.
P4 will execute from time 18 to 38 ms.
P5 will execute from time 38 to 40 ms.
Total waiting time = (10-5) + (8-5) + (18-0) + (38-5) + (40-10) = 5.6 + 3 + 18 + 33 + 30 = 90
Average waiting time = Total waiting time / Number of processes = 90/5 = 5.6 ms
* Using Priority preemptive scheduling
The document discusses different CPU scheduling algorithms:
1. First Come First Served scheduling allocates CPU to the longest waiting process first, which can result in longer processes waiting behind shorter ones (convoy effect).
2. Shortest Job First scheduling allocates CPU to the process with the shortest estimated run time, minimizing average wait time. Preemptive SJF allows interrupting the current process if a shorter one arrives.
3. Priority scheduling assigns priority levels and allocates CPU to the highest priority ready process. Preemption and aging policies address starvation of lower priority processes.
4. Round Robin scheduling allocates a time quantum (e.g. 10-100ms) to each ready process
Similar to Program for FCFS CPU Scheduling.program docx (20)
Embedded machine learning-based road conditions and driving behavior monitoringIJECEIAES
Car accident rates have increased in recent years, resulting in losses in human lives, properties, and other financial costs. An embedded machine learning-based system is developed to address this critical issue. The system can monitor road conditions, detect driving patterns, and identify aggressive driving behaviors. The system is based on neural networks trained on a comprehensive dataset of driving events, driving styles, and road conditions. The system effectively detects potential risks and helps mitigate the frequency and impact of accidents. The primary goal is to ensure the safety of drivers and vehicles. Collecting data involved gathering information on three key road events: normal street and normal drive, speed bumps, circular yellow speed bumps, and three aggressive driving actions: sudden start, sudden stop, and sudden entry. The gathered data is processed and analyzed using a machine learning system designed for limited power and memory devices. The developed system resulted in 91.9% accuracy, 93.6% precision, and 92% recall. The achieved inference time on an Arduino Nano 33 BLE Sense with a 32-bit CPU running at 64 MHz is 34 ms and requires 2.6 kB peak RAM and 139.9 kB program flash memory, making it suitable for resource-constrained embedded systems.
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELgerogepatton
As digital technology becomes more deeply embedded in power systems, protecting the communication
networks of Smart Grids (SG) has emerged as a critical concern. Distributed Network Protocol 3 (DNP3)
represents a multi-tiered application layer protocol extensively utilized in Supervisory Control and Data
Acquisition (SCADA)-based smart grids to facilitate real-time data gathering and control functionalities.
Robust Intrusion Detection Systems (IDS) are necessary for early threat detection and mitigation because
of the interconnection of these networks, which makes them vulnerable to a variety of cyberattacks. To
solve this issue, this paper develops a hybrid Deep Learning (DL) model specifically designed for intrusion
detection in smart grids. The proposed approach is a combination of the Convolutional Neural Network
(CNN) and the Long-Short-Term Memory algorithms (LSTM). We employed a recent intrusion detection
dataset (DNP3), which focuses on unauthorized commands and Denial of Service (DoS) cyberattacks, to
train and test our model. The results of our experiments show that our CNN-LSTM method is much better
at finding smart grid intrusions than other deep learning algorithms used for classification. In addition,
our proposed approach improves accuracy, precision, recall, and F1 score, achieving a high detection
accuracy rate of 99.50%.
International Conference on NLP, Artificial Intelligence, Machine Learning an...gerogepatton
International Conference on NLP, Artificial Intelligence, Machine Learning and Applications (NLAIM 2024) offers a premier global platform for exchanging insights and findings in the theory, methodology, and applications of NLP, Artificial Intelligence, Machine Learning, and their applications. The conference seeks substantial contributions across all key domains of NLP, Artificial Intelligence, Machine Learning, and their practical applications, aiming to foster both theoretical advancements and real-world implementations. With a focus on facilitating collaboration between researchers and practitioners from academia and industry, the conference serves as a nexus for sharing the latest developments in the field.
Using recycled concrete aggregates (RCA) for pavements is crucial to achieving sustainability. Implementing RCA for new pavement can minimize carbon footprint, conserve natural resources, reduce harmful emissions, and lower life cycle costs. Compared to natural aggregate (NA), RCA pavement has fewer comprehensive studies and sustainability assessments.
ACEP Magazine edition 4th launched on 05.06.2024Rahul
This document provides information about the third edition of the magazine "Sthapatya" published by the Association of Civil Engineers (Practicing) Aurangabad. It includes messages from current and past presidents of ACEP, memories and photos from past ACEP events, information on life time achievement awards given by ACEP, and a technical article on concrete maintenance, repairs and strengthening. The document highlights activities of ACEP and provides a technical educational article for members.
Comparative analysis between traditional aquaponics and reconstructed aquapon...bijceesjournal
The aquaponic system of planting is a method that does not require soil usage. It is a method that only needs water, fish, lava rocks (a substitute for soil), and plants. Aquaponic systems are sustainable and environmentally friendly. Its use not only helps to plant in small spaces but also helps reduce artificial chemical use and minimizes excess water use, as aquaponics consumes 90% less water than soil-based gardening. The study applied a descriptive and experimental design to assess and compare conventional and reconstructed aquaponic methods for reproducing tomatoes. The researchers created an observation checklist to determine the significant factors of the study. The study aims to determine the significant difference between traditional aquaponics and reconstructed aquaponics systems propagating tomatoes in terms of height, weight, girth, and number of fruits. The reconstructed aquaponics system’s higher growth yield results in a much more nourished crop than the traditional aquaponics system. It is superior in its number of fruits, height, weight, and girth measurement. Moreover, the reconstructed aquaponics system is proven to eliminate all the hindrances present in the traditional aquaponics system, which are overcrowding of fish, algae growth, pest problems, contaminated water, and dead fish.
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Program for FCFS CPU Scheduling.program docx
1. Program for FCFS CPU Scheduling | Set 1
Last Updated : 21 Jul, 2023
Given n processes with their burst times, the task is to find average waiting time
and average turn around time using FCFS scheduling algorithm.
First in, first out (FIFO), also known as first come, first served (FCFS), is the
simplest scheduling algorithm. FIFO simply queues processes in the order that
they arrive in the ready queue.
In this, the process that comes first will be executed first and next process starts
only after the previous gets fully executed.
Here we are considering that arrival time for all processes is 0.
How to compute below times in Round Robin using a program?
1. Completion Time: Time at which process completes its execution.
2. Turn Around Time: Time Difference between completion time and arrival
time. Turn Around Time = Completion Time – Arrival Time
3. Waiting Time(W.T): Time Difference between turn around time and burst
time.
Waiting Time = Turn Around Time – Burst Time
In this post, we have assumed arrival times as 0, so turn around and
completion times are same.
2. Implementation:
1- Input the processes along with their burst time (bt).
2- Find waiting time (wt) for all processes.
3- As first process that comes need not to wait so
waiting time for process 1 will be 0 i.e. wt[0] = 0.
4- Find waiting time for all other processes i.e. for
process i ->
wt[i] = bt[i-1] + wt[i-1] .
5- Find turnaround time = waiting_time + burst_time
for all processes.
6- Find average waiting time =
total_waiting_time / no_of_processes.
7- Similarly, find average turnaround time =
total_turn_around_time / no_of_processes.
3. Program for FCFS CPU Scheduling | Set 2
(Processes with different arrival times)
Last Updated : 13 Sep, 2023
We have already discussed FCFS Scheduling of processes with same arrival
time. In this post, scenarios, when processes have different arrival times, are
discussed. Given n processes with their burst times and arrival times, the task
is to find the average waiting time and an average turn around time using
FCFS scheduling algorithm.
FIFO simply queues processes in the order they arrive in the ready queue.
Here, the process that comes first will be executed first and next process will
start only after the previous gets fully executed.
1. Completion Time: Time at which the process completes its execution.
2. Turn Around Time: Time Difference between completion time and arrival
time. Turn Around Time = Completion Time – Arrival Time
3. Waiting Time(W.T): Time Difference between turn around time and burst
time.
Waiting Time = Turn Around Time – Burst Time.
4. Process Wait Time : Service Time - Arrival Time
P0 0 - 0 = 0
P1 5 - 1 = 4
P2 8 - 2 = 6
P3 16 - 3 = 13
Average Wait Time: (0 + 4 + 6 + 13) / 4 = 5.75
Service Time: Also known as Burst Time, this is the amount of time a
process requires to complete its execution on the CPU. It represents the time
the CPU spends executing instructions of that particular process.
Waiting Time: It refers to the total amount of time that a process spends
waiting in the ready queue before it gets a chance to execute on the CPU.
5. Program for Shortest Job First (or SJF) CPU
Scheduling | Set 1 (Non- preemptive)
Last Updated : 24 Mar, 2023
The shortest job first (SJF) or shortest job next, is a scheduling policy that selects
the waiting process with the smallest execution time to execute next. SJN, also
known as Shortest Job Next (SJN), can be preemptive or non-preemptive.
Characteristics of SJF Scheduling:
Shortest Job first has the advantage of having a minimum average waiting
time among all scheduling algorithms.
It is a Greedy Algorithm.
It may cause starvation if shorter processes keep coming. This problem can be
solved using the concept of ageing.
It is practically infeasible as Operating System may not know burst times and
therefore may not sort them. While it is not possible to predict execution time,
several methods can be used to estimate the execution time for a job, such as
a weighted average of previous execution times.
SJF can be used in specialized environments where accurate estimates of
running time are available.
Algorithm:
Sort all the processes according to the arrival time.
Then select that process that has minimum arrival time and minimum Burst
time.
After completion of the process make a pool of processes that arrives
afterward till the completion of the previous process and select that process
among the pool which is having minimum Burst time.
6. Shortest Job First Scheduling Algorithm
How to compute below times in SJF using a program?
Completion Time: Time at which process completes its execution.
Turn Around Time: Time Difference between completion time and arrival
time.
Turn Around Time = Completion Time – Arrival Time
Waiting Time(W.T): Time Difference between turn around time and burst
time.
Waiting Time = Turn Around Time – Burst Time
Program for Non-Preemptive Shortest Job First CPU Scheduling
Non-Preemptive Shortest Job First algorithm can be implemented using Segment
Trees data structure. For detailed implementation of Non-Preemptive Shortest
Job First scheduling algorithm, please refer: Program for Non-Preemptive
Shortest Job First CPU Scheduling.
In this post, we have assumed arrival times as 0, so turn around and
completion times are same.
Examples to show working of Non-Preemptive Shortest Job First CPU
Scheduling Algorithm:
Example-1: Consider the following table of arrival time and burst time for five
processes P1, P2, P3, P4 and P5.
7. Process Burst Time Arrival Time
P1 6 ms 2 ms
P2 2 ms 5 ms
P3 8 ms 1 ms
P4 3 ms 0 ms
P5 4 ms 4 ms
The Shortest Job First CPU Scheduling Algorithm will work on the basis of steps
as mentioned below:
At time = 0,
Process P4 arrives and starts executing
Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
0-1ms P4 0ms 1ms 3ms 2ms
At time= 1,
Process P3 arrives.
But, as P4 still needs 2 execution units to complete.
Thus, P3 will wait till P4 gets executed.
8. Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
1-2ms
P4 0ms 1ms 2ms 1ms
P3 1ms P3 0ms 8ms 8ms
At time =2,
Process P1 arrives and is added to the waiting table
P4 will continue its execution.
Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
2-3ms
P4 0ms 1ms 1ms 0ms
P3 1ms P3 0ms 8ms 8ms
P1 2ms P3, P1 0ms 6ms 6ms
At time = 3,
Process P4 will finish its execution.
Then, the burst time of P3 and P1 is compared.
Process P1 is executed because its burst time is less as compared to P3.
Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
3-4ms P3 1ms P3 0ms 8ms 8ms
9. Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
P1 2ms P3 1ms 6ms 5ms
At time = 4,
Process P5 arrives and is added to the waiting Table.
P1 will continue execution.
Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
4-5ms
P3 1ms P3 0ms 8ms 8ms
P1 2ms P3 1ms 5ms 4ms
P5 4ms P3, P5 0ms 4ms 4ms
At time = 5,
Process P2 arrives and is added to the waiting Table.
P1 will continue execution.
Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
5-6ms
P3 1ms P3 0ms 8ms 8ms
P1 2ms P3 1ms 4ms 3ms
10. Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
P5 4ms P3, P5 0ms 4ms 4ms
P2 5ms P3, P5, P2 0ms 2ms 2ms
At time = 6,
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 among all.
Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
6-9ms
P3 1ms P3 0ms 8ms 8ms
P1 2ms P3 3ms 3ms 0ms
P5 4ms P3, P5 0ms 4ms 4ms
P2 5ms P3, P5, P2 0ms 2ms 2ms
At time=9,
Process P2 is executing and P3 and P5 are in the waiting Table.
11. Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
9-11ms
P3 1ms P3 0ms 8ms 8ms
P5 4ms P3, P5 0ms 4ms 4ms
P2 5ms P3, P5 2ms 2ms 0ms
At time = 11,
The execution of Process P2 will be done.
The burst time of P3 and P5 is compared.
Process P5 is executed because its burst time is lower than P3.
Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
11-15ms
P3 1ms P3 0ms 8ms 8ms
P5 4ms P3 4ms 4ms 0ms
At time = 15,
Process P5 will finish its execution.
Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
15-23ms P3 1ms 8ms 8ms 0ms
At time = 23,
Process P3 will finish its execution.
12. The overall execution of the processes will be as shown below:
Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
0-1ms P4 0ms 1ms 3ms 2ms
1-2ms
P4 0ms 1ms 2ms 1ms
P3 1ms P3 0ms 8ms 8ms
2-3ms
P4 0ms 1ms 1ms 0ms
P3 1ms P3 0ms 8ms 8ms
P1 2ms P3, P1 0ms 6ms 6ms
3-4ms
P3 1ms P3 0ms 8ms 8ms
P1 2ms P3 1ms 6ms 5ms
4-5ms
P3 1ms P3 0ms 8ms 8ms
P1 2ms P3 1ms 5ms 4ms
P5 4ms P3, P5 0ms 4ms 4ms
5-6ms P3 1ms P3 0ms 8ms 8ms
14. Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
15-23ms P3 1ms 8ms 8ms 0ms
Gantt chart for above execution:
Gantt chart
Now, let’s calculate the average waiting time for above example:
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.2
Advantages of SJF:
SJF is better than the First come first serve(FCFS) algorithm as it reduces the
average waiting time.
SJF is generally used for long term scheduling
It is suitable for the jobs running in batches, where run times are already
known.
SJF is probably optimal in terms of average turnaround time.
Disadvantages of SJF:
SJF may cause very long turn-around times or starvation.
In SJF job completion time must be known earlier, but sometimes it is hard to
predict.
Sometimes, it is complicated to predict the length of the upcoming CPU
request.
It leads to the starvation that does not reduce average turnaround time.
15. Shortest Remaining Time First (Preemptive SJF)
Scheduling Algorithm
Last Updated : 07 May, 2024
In previous post, we have discussed Set 1 of SJF i.e. non-pre-emptive. In
this post we will discuss the pre-emptive version of SJF known as Shortest
Remaining Time First (SRTF).
In the Shortest Remaining Time First (SRTF) scheduling algorithm, the
process with the smallest amount of time remaining until completion is
selected to execute. Since the currently executing process is the one with
the shortest amount of time remaining by definition, and since that time
should only reduce as execution progresses, processes will always run until
they complete or a new process is added that requires a smaller amount of
time.
Examples to show working of Pre-emptive Shortest Job First CPU
Scheduling Algorithm:
Example-1: Consider the following table of arrival time and burst time for five
processes P1, P2, P3, P4 and P5.
Process Burst Time Arrival Time
P1 6 ms 2 ms
P2 2 ms 5 ms
P3 8 ms 1 ms
P4 3 ms 0 ms
P5 4 ms 4 ms
The Shortest Job First CPU Scheduling Algorithm will work on the basis of
steps as mentioned below:
At time = 0,
Process P4 arrives and starts executing
16. Time
Instanc
e
Proces
s
Arriva
l Time
Waitin
g
Table
Executio
n Time
Initia
l
Burs
t
Time
Remainin
g Burst
Time
0-1ms P4 0ms 1ms 3ms 2ms
At time= 1,
Process P3 arrives.
But, as P4 has a shorter burst time. It will continue execution.
Thus, P3 will wait till P4 gets executed.
Time
Instanc
e
Proces
s
Arriva
l Time
Waitin
g
Table
Executio
n Time
Initia
l
Burs
t
Time
Remainin
g Burst
Time
1-2ms
P4 0ms
P3
1ms 2ms 1ms
P3 1ms 0ms 8ms 8ms
At time =2,
Process P1 arrives with burst time = 6
As the burst time of P1 is more than that of P4
Thus, P4 will continue its execution.
Time
Instanc
e
Proces
s
Arriva
l Time
Waitin
g
Table
Executio
n Time
Initia
l
Burs
t
Time
Remainin
g Burst
Time
2-3ms
P4 0ms
P3,
P1
1ms 1ms 0ms
P3 1ms 0ms 8ms 8ms
P1 2ms 0ms 6ms 6ms
At time = 3,
17. Process P4 will finish its execution.
Then, the burst time of P3 and P1 is compared.
Process P1 is executed because its burst time is less as compared to P3.
Time
Instanc
e
Proces
s
Arriva
l Time
Waitin
g
Table
Executio
n Time
Initia
l
Burs
t
Time
Remainin
g Burst
Time
3-4ms
P3 1ms
P
3
0ms 8ms 8ms
P1 2ms 1ms 6ms 5ms
At time = 4,
Process P5 arrives.
Then the burst time of P3, P5, and P1 is compared.
Process P5 gets executed first among them because its burst time is
lowest, and process P1 is preempted.
Time
Instanc
e
Proces
s
Arriva
l Time
Waitin
g
Table
Executio
n Time
Initia
l
Burs
t
Time
Remainin
g Burst
Time
4-5ms
P3 1ms
P3,
P1
0ms 8ms 8ms
P1 2ms 0ms 5ms 5ms
P5 4ms 1ms 4ms 3ms
At time = 5,
Process P2 arrives.
The burst time of all processes are compared,
Process P2 gets executed as its burst time is lowest among all.
Process P5 is preempted.
18. Time
Instanc
e
Proces
s
Arriva
l Time
Waitin
g
Table
Executio
n Time
Initia
l
Burs
t
Time
Remainin
g Burst
Time
5-6ms
P3 1ms
P3,
P5, P1
0ms 8ms 8ms
P1 2ms 0ms 5ms 5ms
P5 4ms 0ms 3ms 3ms
P2 5ms 1ms 2ms 1ms
At time = 6,
Process P2 will keep executing.
It will execute till time = 7 as the burst time of P2 is 2ms
Time
Instanc
e
Proces
s
Arriva
l Time
Waitin
g
Table
Executio
n Time
Initia
l
Burs
t
Time
Remainin
g Burst
Time
6-7ms
P3 1ms
P3, P5,
P1
0ms 8ms 8ms
P1 2ms 0ms 5ms 5ms
P5 4ms 0ms 3ms 3ms
P2 5ms 1ms 1ms 0ms
At time=7,
The process P2 finishes its execution.
Then again the burst time of all remaining processes is compared.
The Process P5 gets executed because its burst time is lesser than the
others.
19. Time
Instanc
e
Proces
s
Arriva
l Time
Waitin
g
Table
Executio
n Time
Initia
l
Burs
t
Time
Remainin
g Burst
Time
7-10ms
P3 1ms
P3, P1
0ms 8ms 8ms
P1 2ms 0ms 5ms 5ms
P5 4ms 3ms 3ms 0ms
At time = 10,
The process P5 will finish its execution.
Then the burst time of the remaining processes P1 and P3 is compared.
Thus, process P1 is executed as its burst time is less than P3
Time
Instanc
e
Proces
s
Arriva
l Time
Waitin
g
Table
Executio
n Time
Initia
l
Burs
t
Time
Remainin
g Burst
Time
10-
15ms
P3 1ms
P3
0ms 8ms 8ms
P1 4ms 4ms 5ms 0ms
At time = 15,
The process P1 finishes its execution and P3 is the only process left.
P3 will start executing.
Time
Instanc
e
Proces
s
Arriva
l Time
Waitin
g
Table
Executio
n Time
Initia
l
Burs
t
Time
Remainin
g Burst
Time
15-
23ms
P3 1ms 8ms 8ms 0ms
At time = 23,
20. Process P3 will finish its execution.
The overall execution of the processes will be as shown below:
Time
Instanc
e
Proces
s
Arriva
l Time
Waitin
g
Table
Executio
n Time
Initia
l
Burs
t
Time
Remainin
g Burst
Time
0-1ms P4 0ms 1ms 3ms 2ms
1-2ms
P4 0ms
P3
1ms 2ms 1ms
P3 1ms 0ms 8ms 8ms
2-3ms
P4 0ms
P3,
P1
1ms 1ms 0ms
P3 1ms 0ms 8ms 8ms
P1 2ms 0ms 6ms 6ms
3-4ms
P3 1ms
P3
0ms 8ms 8ms
P1 2ms 1ms 6ms 5ms
4-5ms
P3 1ms
P3,
P1
0ms 8ms 8ms
P1 2ms 0ms 5ms 5ms
P5 4ms 1ms 4ms 3ms
5-6ms
P3 1ms
P3,
P5, P1
0ms 8ms 8ms
P1 2ms 0ms 5ms 5ms
P5 4ms 0ms 3ms 3ms
21. Time
Instanc
e
Proces
s
Arriva
l Time
Waitin
g
Table
Executio
n Time
Initia
l
Burs
t
Time
Remainin
g Burst
Time
P2 5ms 1ms 2ms 1ms
6-7ms
P3 1ms
P3,
P5, P1
0ms 8ms 8ms
P1 2ms 0ms 5ms 5ms
P5 4ms 0ms 3ms 3ms
P2 5ms 1ms 1ms 0ms
7-10ms
P3 1ms
P3, P1
0ms 8ms 8ms
P1 2ms 0ms 5ms 5ms
P5 4ms 3ms 3ms 0ms
10-
15ms
P3 1ms
P3
0ms 8ms 8ms
P1 4ms 4ms 5ms 0ms
15-
23ms
P3 1ms 8ms 8ms 0ms
Gantt chart for above execution:
Gantt chart for SRTF
Now, lets calculate average waiting time and turn around time:
As we know,
Turn Around time = Completion time – arrival time
22. Waiting Time = Turn around time – burst time
Process
Completion
Time
Turn Around
Time Waiting Time
P1 15 15-2 = 13 13-6 = 7
P2 7 7-5 = 2 2-2 = 0
P3 23 23-1 = 22 22-8 = 14
P4 3 3-0 = 3 3-3 = 0
P5 10 10-4 = 6 6-4 = 2
Now,
Average Turn around time = (13 + 2 + 22 + 3 + 6)/5 = 9.2
Average waiting time = (7 + 0 + 14 + 0 + 2)/5 = 23/5 = 4.6
Some of the key characteristics of SRTF
Preemptive: SRTF is a preemptive algorithm, which means that the
currently running process can be interrupted if a new process arrives with
a shorter burst time. This helps in ensuring that the processes with the
shortest burst times are executed first.
Dynamic: SRTF is a dynamic algorithm, which means that it can adapt to
changes in the arrival time and burst time of processes. It constantly re-
evaluates the remaining burst time of each process and schedules the
process with the shortest remaining time.
Low waiting time: SRTF is known for its low waiting time. By selecting the
process with the shortest remaining burst time, it ensures that the
processes with the shortest burst times are executed first, which reduces
the average waiting time of processes.
SRTF has a higher complexity than other scheduling algorithms like FCFS
(First Come First Serve) and RR (Round Robin), because it requires
frequent context switches and preemptions.
Implementation of SRTF Algorithm:
Approach:
Traverse until all process gets completely executed.
Find process with minimum remaining time at every single time
lap.
Reduce its time by 1.
Check if its remaining time becomes 0
23. Increment the counter of process completion.
Completion time of current process = current_time + 1;
Calculate waiting time for each completed process.
wt[i]= Completion time – arrival_time-burst_time
Increment time lap by one.
Find turnaround time (waiting_time + burst_time).
Shortest Remaining Time First (Preemptive SJF)
Scheduling Algorithm
Last Updated : 07 May, 2024
In previous post, we have discussed Set 1 of SJF i.e. non-pre-emptive. In
this post we will discuss the pre-emptive version of SJF known as Shortest
Remaining Time First (SRTF).
In the Shortest Remaining Time First (SRTF) scheduling algorithm, the
process with the smallest amount of time remaining until completion is
selected to execute. Since the currently executing process is the one with
the shortest amount of time remaining by definition, and since that time
should only reduce as execution progresses, processes will always run until
24. they complete or a new process is added that requires a smaller amount of
time.
Examples to show working of Pre-emptive Shortest Job First CPU
Scheduling Algorithm:
Example-1: Consider the following table of arrival time and burst time for five
processes P1, P2, P3, P4 and P5.
Process Burst Time Arrival Time
P1 6 ms 2 ms
P2 2 ms 5 ms
P3 8 ms 1 ms
P4 3 ms 0 ms
P5 4 ms 4 ms
The Shortest Job First CPU Scheduling Algorithm will work on the basis of
steps as mentioned below:
At time = 0,
Process P4 arrives and starts executing
Time
Instanc
e
Proces
s
Arriva
l Time
Waitin
g
Table
Executio
n Time
Initia
l
Burs
t
Time
Remainin
g Burst
Time
0-1ms P4 0ms 1ms 3ms 2ms
At time= 1,
Process P3 arrives.
But, as P4 has a shorter burst time. It will continue execution.
Thus, P3 will wait till P4 gets executed.
25. Time
Instanc
e
Proces
s
Arriva
l Time
Waitin
g
Table
Executio
n Time
Initia
l
Burs
t
Time
Remainin
g Burst
Time
1-2ms
P4 0ms
P3
1ms 2ms 1ms
P3 1ms 0ms 8ms 8ms
At time =2,
Process P1 arrives with burst time = 6
As the burst time of P1 is more than that of P4
Thus, P4 will continue its execution.
Time
Instanc
e
Proces
s
Arriva
l Time
Waitin
g
Table
Executio
n Time
Initia
l
Burs
t
Time
Remainin
g Burst
Time
2-3ms
P4 0ms
P3,
P1
1ms 1ms 0ms
P3 1ms 0ms 8ms 8ms
P1 2ms 0ms 6ms 6ms
At time = 3,
Process P4 will finish its execution.
Then, the burst time of P3 and P1 is compared.
Process P1 is executed because its burst time is less as compared to P3.
Time
Instanc
e
Proces
s
Arriva
l Time
Waitin
g
Table
Executio
n Time
Initia
l
Burs
t
Time
Remainin
g Burst
Time
3-4ms P3 1ms 0ms 8ms 8ms
26. Time
Instanc
e
Proces
s
Arriva
l Time
Waitin
g
Table
Executio
n Time
Initia
l
Burs
t
Time
Remainin
g Burst
Time
P1 2ms
P
3
1ms 6ms 5ms
At time = 4,
Process P5 arrives.
Then the burst time of P3, P5, and P1 is compared.
Process P5 gets executed first among them because its burst time is
lowest, and process P1 is preempted.
Time
Instanc
e
Proces
s
Arriva
l Time
Waitin
g
Table
Executio
n Time
Initia
l
Burs
t
Time
Remainin
g Burst
Time
4-5ms
P3 1ms
P3,
P1
0ms 8ms 8ms
P1 2ms 0ms 5ms 5ms
P5 4ms 1ms 4ms 3ms
At time = 5,
Process P2 arrives.
The burst time of all processes are compared,
Process P2 gets executed as its burst time is lowest among all.
Process P5 is preempted.
Time
Instanc
e
Proces
s
Arriva
l Time
Waitin
g
Table
Executio
n Time
Initia
l
Burs
t
Time
Remainin
g Burst
Time
5-6ms P3 1ms 0ms 8ms 8ms
27. Time
Instanc
e
Proces
s
Arriva
l Time
Waitin
g
Table
Executio
n Time
Initia
l
Burs
t
Time
Remainin
g Burst
Time
P1 2ms
P3,
P5, P1
0ms 5ms 5ms
P5 4ms 0ms 3ms 3ms
P2 5ms 1ms 2ms 1ms
At time = 6,
Process P2 will keep executing.
It will execute till time = 7 as the burst time of P2 is 2ms
Time
Instanc
e
Proces
s
Arriva
l Time
Waitin
g
Table
Executio
n Time
Initia
l
Burs
t
Time
Remainin
g Burst
Time
6-7ms
P3 1ms
P3, P5,
P1
0ms 8ms 8ms
P1 2ms 0ms 5ms 5ms
P5 4ms 0ms 3ms 3ms
P2 5ms 1ms 1ms 0ms
At time=7,
The process P2 finishes its execution.
Then again the burst time of all remaining processes is compared.
The Process P5 gets executed because its burst time is lesser than the
others.
28. Time
Instanc
e
Proces
s
Arriva
l Time
Waitin
g
Table
Executio
n Time
Initia
l
Burs
t
Time
Remainin
g Burst
Time
7-10ms
P3 1ms
P3, P1
0ms 8ms 8ms
P1 2ms 0ms 5ms 5ms
P5 4ms 3ms 3ms 0ms
At time = 10,
The process P5 will finish its execution.
Then the burst time of the remaining processes P1 and P3 is compared.
Thus, process P1 is executed as its burst time is less than P3
Time
Instanc
e
Proces
s
Arriva
l Time
Waitin
g
Table
Executio
n Time
Initia
l
Burs
t
Time
Remainin
g Burst
Time
10-
15ms
P3 1ms
P3
0ms 8ms 8ms
P1 4ms 4ms 5ms 0ms
At time = 15,
The process P1 finishes its execution and P3 is the only process left.
P3 will start executing.
Time
Instanc
e
Proces
s
Arriva
l Time
Waitin
g
Table
Executio
n Time
Initia
l
Burs
t
Time
Remainin
g Burst
Time
15-
23ms
P3 1ms 8ms 8ms 0ms
At time = 23,
29. Process P3 will finish its execution.
The overall execution of the processes will be as shown below:
Time
Instanc
e
Proces
s
Arriva
l Time
Waitin
g
Table
Executio
n Time
Initia
l
Burs
t
Time
Remainin
g Burst
Time
0-1ms P4 0ms 1ms 3ms 2ms
1-2ms
P4 0ms
P3
1ms 2ms 1ms
P3 1ms 0ms 8ms 8ms
2-3ms
P4 0ms
P3,
P1
1ms 1ms 0ms
P3 1ms 0ms 8ms 8ms
P1 2ms 0ms 6ms 6ms
3-4ms
P3 1ms
P3
0ms 8ms 8ms
P1 2ms 1ms 6ms 5ms
4-5ms
P3 1ms
P3,
P1
0ms 8ms 8ms
P1 2ms 0ms 5ms 5ms
P5 4ms 1ms 4ms 3ms
5-6ms
P3 1ms
P3,
P5, P1
0ms 8ms 8ms
P1 2ms 0ms 5ms 5ms
P5 4ms 0ms 3ms 3ms
30. Time
Instanc
e
Proces
s
Arriva
l Time
Waitin
g
Table
Executio
n Time
Initia
l
Burs
t
Time
Remainin
g Burst
Time
P2 5ms 1ms 2ms 1ms
6-7ms
P3 1ms
P3,
P5, P1
0ms 8ms 8ms
P1 2ms 0ms 5ms 5ms
P5 4ms 0ms 3ms 3ms
P2 5ms 1ms 1ms 0ms
7-10ms
P3 1ms
P3, P1
0ms 8ms 8ms
P1 2ms 0ms 5ms 5ms
P5 4ms 3ms 3ms 0ms
10-
15ms
P3 1ms
P3
0ms 8ms 8ms
P1 4ms 4ms 5ms 0ms
15-
23ms
P3 1ms 8ms 8ms 0ms
Gantt chart for above execution:
Gantt chart for SRTF
Now, lets calculate average waiting time and turn around time:
As we know,
Turn Around time = Completion time – arrival time
31. Waiting Time = Turn around time – burst time
Process
Completion
Time
Turn Around
Time Waiting Time
P1 15 15-2 = 13 13-6 = 7
P2 7 7-5 = 2 2-2 = 0
P3 23 23-1 = 22 22-8 = 14
P4 3 3-0 = 3 3-3 = 0
P5 10 10-4 = 6 6-4 = 2
Now,
Average Turn around time = (13 + 2 + 22 + 3 + 6)/5 = 9.2
Average waiting time = (7 + 0 + 14 + 0 + 2)/5 = 23/5 = 4.6
Some of the key characteristics of SRTF
Preemptive: SRTF is a preemptive algorithm, which means that the
currently running process can be interrupted if a new process arrives with
a shorter burst time. This helps in ensuring that the processes with the
shortest burst times are executed first.
Dynamic: SRTF is a dynamic algorithm, which means that it can adapt to
changes in the arrival time and burst time of processes. It constantly re-
evaluates the remaining burst time of each process and schedules the
process with the shortest remaining time.
Low waiting time: SRTF is known for its low waiting time. By selecting the
process with the shortest remaining burst time, it ensures that the
processes with the shortest burst times are executed first, which reduces
the average waiting time of processes.
SRTF has a higher complexity than other scheduling algorithms like FCFS
(First Come First Serve) and RR (Round Robin), because it requires
frequent context switches and preemptions.
Implementation of SRTF Algorithm:
Approach:
Traverse until all process gets completely executed.
Find process with minimum remaining time at every single time
lap.
Reduce its time by 1.
Check if its remaining time becomes 0
32. Increment the counter of process completion.
Completion time of current process = current_time + 1;
Calculate waiting time for each completed process.
wt[i]= Completion time – arrival_time-burst_time
Increment time lap by one.
Find turnaround time (waiting_time + burst_time).
33. Longest Remaining Time First (LRTF) CPU
Scheduling Program
Last Updated : 10 May, 2023
We have given some processes with arrival time and Burst Time and we have to
find the completion time (CT), Turn Around Time(TAT), Average Turn Around
Time (Avg TAT), Waiting Time(WT), Average Waiting Time (AWT) for the given
processes.
Prerequisite: CPU Scheduling | Longest Remaining Time First (LRTF)
algorithm
LRTF is a preemptive scheduling algorithm. Its tie-breaker is FCFS and if FCFS
does not breaks the tie then, we use process id as the tie-breaker.
Example: Consider the following table of arrival time and burst time for four
processes P1, P2, P3, and P4.
Process Arrival time Burst Time
P1 1 ms 2 ms
P2 2 ms 4 ms
P3 3 ms 6 ms
p4 4 ms 8 ms
Gantt chart will be as following below,
Since completion time (CT) can be directly determined by Gantt chart, and
Turn Around Time (TAT)
= (Completion Time) - (Arrival Time)
Also, Waiting Time (WT)
= (Turn Around Time) - (Burst Time)
Therefore,
Output:
34. Total Turn Around Time = 68 ms
So, Average Turn Around Time = 68/4 = 17.00 ms
And, Total Waiting Time = 48 ms
So, Average Waiting Time = 12.00 ms
Algorithm:
Step 1: Create a structure of process containing all necessary fields like AT
(Arrival Time), BT(Burst Time), CT(Completion Time), TAT(Turn Around
Time), WT(Waiting Time).
Step 2: Sort the processes according to their arrival time (AT).
Step 3: Initialize the current time (time variable) as 0, and find the process
with the largest burst time (BT) among all the processes that have arrived till
now. Execute that process for each single unit, i.e., increase the time variable
by 1 and reduce the BT of that process by 1.
Step 4: If any process completes its execution, update its CT(Completion
Time) as the current time (time variable).
Step 5: If the BT of the executing process becomes 0, then update its CT as the
current time (time variable) and remove it from the list of processes to be
executed.
Step 6: If all processes have been executed, exit the loop.
Step 7: After calculating the CT for each process, find the TAT (Turn Around
Time) and WT (Waiting Time).
(TAT = CT - AT)
(WT = TAT - BT)
Implementation of Algorithm3s
35. Longest Remaining Time First (LRTF) or
Preemptive Longest Job First CPU Scheduling
Algorithm
Last Updated : 12 Mar, 2024
Longest Remaining Time First (LRTF) is a preemptive version of Longest Job
First (LJF) scheduling algorithm. In this scheduling algorithm, we find the
process with the maximum remaining time and then process it, i.e. check for the
maximum remaining time after some interval of time(say 1 unit each) to check if
another process having more Burst Time arrived up to that time.
Characteristics of Longest Remaining Time First (LRTF)
Among all the processes waiting in a waiting queue, CPU is always assigned to
the process having largest burst time.
If two processes have the same burst time then the tie is broken
using FCFS i.e. the process that arrived first is processed first.
LJF CPU Scheduling can be of both preemptive and non-preemptive type.
Advantages of Longest Remaining Time First (LRTF)
No other process can execute until the longest job or process executes
completely.
All the jobs or processes finishes at the same time approximately.
Disadvantages of Longest Remaining Time First (LRTF)
This algorithm gives very high average waiting time and average turn-around
time for a given set of processes.
This may lead to convoy effect.
It may happen that a short process may never get executed and the system
keeps on executing the longer processes.
It reduces the processing speed and thus reduces the efficiency and utilization
of the system.
Longest Remaining Time First (LRTF) CPU Scheduling Algorithm
Step-1: First, sort the processes in increasing order of their Arrival Time.
Step-2: Choose the process having least arrival time but with most Burst
Time.
Step-3: Then process it for 1 unit. Check if any other process arrives upto that
time of execution or not.
36. Step-4: Repeat the above both steps until execute all the processes.
Examples to show working of Preemptive Longest Job First CPU Scheduling
Algorithm:
Example-1: Consider the following table of arrival time and burst time for four
processes P1, P2, P3 and P4.
Processes Arrival time Burst Time
P1 1 ms 2 ms
P2 2 ms 4 ms
P3 3 ms 6 ms
P4 4 ms 8 ms
The Longest Remaining Time First CPU Scheduling Algorithm will work on
the basis of steps as mentioned below:
At time = 1,
Available Process : P1. So, select P1 and execute 1 ms.
Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
1-2ms P1 1ms 1ms 2ms 1ms
At time = 2,
Available Process : P1, P2.
So, select P2 and execute 1 ms (since B.T(P1) = 1 which is less than B.T(P2) =
4)
37. Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
2-3ms
P1 1ms
P1
0ms 1ms 1ms
P2 2ms 1ms 4ms 3ms
At time = 3,
Available Process : P1, P2, P3.
So, select P3 and execute 1 ms (since, B.T(P1) = 1 , B.T(P2) = 3 , B.T(P3) = 6).
Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
3-4ms
P1 1ms
P1, P2
0ms 1ms 1ms
P2 2ms 0ms 3ms 3ms
P3 3ms 1ms 6ms 5ms
At time = 4,
Available processes: P1, P2, P3, P4.
So, select P4 (as burst time of P4 is largest) and execute 1 ms (since, B.T(P1) =
1 , B.T(P2) = 3 , B.T(P3) = 5, B.T(P4) = 8).
Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
4-5ms P1 1ms 0ms 1ms 1ms
38. Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
P2 2ms
P1, P2,
P3
0ms 3ms 3ms
P3 3ms 0ms 5ms 5ms
P4 4ms 1ms 8ms 7ms
At time = 5,
Available processes: P1, P2, P3, P4,
Process P4 will continue its execution as no other process has burst time
larger than the Process P4
Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
5-7ms
P1 1ms
P1, P2,
P3
0ms 1ms 1ms
P2 2ms 0ms 3ms 3ms
P3 3ms 0ms 5ms 5ms
P4 4ms 2ms 7ms 5ms
At time = 7,
The processes P3 and P4 have same remaining burst time,
hence If two processes have the same burst time then the tie is broken
using FCFS i.e. the process that arrived first is processed first.
Therefore P3 will get executed for 1ms
39. Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
7-8ms
P1 1ms
P1, P2,
P4
0ms 1ms 1ms
P2 2ms 0ms 3ms 3ms
P3 3ms 1ms 5ms 4ms
P4 4ms 0ms 5ms 5ms
At time = 8,
Available processes: P1, P2, P3, P4,
Process P4 will again continue its execution as no other process has burst
time larger than the Process P4
Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
8-9ms
P1 1ms
P1, P2,
P3
0ms 1ms 1ms
P2 2ms 0ms 3ms 3ms
P3 3ms 0ms 4ms 4ms
P4 4ms 1ms 5ms 4ms
At time = 9,
Available processes: P1, P2, P3, P4,
Process P3 continue its execution on the basis of FCFS rule.
40. Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
9-10ms
P1 1ms
P1, P2,
P4
0ms 1ms 1ms
P2 2ms 0ms 3ms 3ms
P3 3ms 1ms 4ms 3ms
P4 4ms 0ms 4ms 4ms
At time = 10,
Available processes: P1, P2, P3, P4,
Now again the burst time of P4 is largest, thus it will execute further.
Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
10-
11ms
P1 1ms
P1, P2,
P3
0ms 1ms 1ms
P2 2ms 0ms 3ms 3ms
P3 3ms 0ms 3ms 3ms
P4 4ms 1ms 4ms 3ms
At time = 11,
Available processes: P1, P2, P3, P4,
Process P2 will continue its execution as the burst time of P2, P3, P4 is same
41. Thus, in this case the further execution will be decided on the basis of FCFS i.e.
the process that arrived first is processed first.
Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
11-
12ms
P1 1ms
P1, P3,
P4
0ms 1ms 1ms
P2 2ms 1ms 3ms 2ms
P3 3ms 0ms 3ms 3ms
P4 4ms 0ms 3ms 3ms
At time = 12,
Available processes: P1, P2, P3, P4,
Process P3 continue its execution on the basis of above explanation.
Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
12-
13ms
P1 1ms
P1, P2,
P4
0ms 1ms 1ms
P2 2ms 0ms 2ms 2ms
P3 3ms 1ms 3ms 2ms
P4 4ms 0ms 3ms 3ms
At time = 13,
Available processes: P1, P2, P3, P4,
42. Now again the burst time of P4 is largest, thus it will execute further.
Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
13-
14ms
P1 1ms
P1, P2,
P3
0ms 1ms 1ms
P2 2ms 0ms 2ms 2ms
P3 3ms 0ms 2ms 2ms
P4 4ms 1ms 3ms 2ms
At time = 14,
Available processes: P1, P2, P3, P4
Now, the process P2 will again begin to execute first among all
Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
14-
15ms
P1 1ms
P1, P3,
P4
0ms 1ms 1ms
P2 2ms 1ms 2ms 1ms
P3 3ms 0ms 2ms 2ms
P4 4ms 0ms 2ms 2ms
At time = 15,
Available processes: P1, P2, P3, P4, now P3 will execute
43. Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
15-
16ms
P1 1ms
P1, P2,
P4
0ms 1ms 1ms
P2 2ms 0ms 1ms 1ms
P3 3ms 1ms 2ms 1ms
P4 4ms 0ms 2ms 2ms
At time = 16,
Available processes: P1, P2, P3, P4,
here, P4 will execute as it has the largest Burst time among all
Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
16-
17ms
P1 1ms
P1, P2,
P3
0ms 1ms 1ms
P2 2ms 0ms 1ms 1ms
P3 3ms 0ms 1ms 1ms
P4 4ms 1ms 2ms 1ms
At time = 17,
Available processes: P1, P2, P3, P4,
Process P1 will execute here on the basis of above explanation
44. Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
17-
18ms
P1 1ms
P2, P3,
P4
1ms 1ms 0ms
P2 2ms 0ms 1ms 1ms
P3 3ms 0ms 1ms 1ms
P4 4ms 0ms 1ms 1ms
At time = 18,
Available processes: P2, P3, P4,
Process P2 will execute.
Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
18-
19ms
P2 2ms
P3, P4
1ms 1ms 0ms
P3 3ms 0ms 1ms 1ms
P4 4ms 0ms 1ms 1ms
At time = 19,
Available processes: P3, P4,
Process P3 will execute.
45. Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
19-
20ms
P3 3ms
P4
1ms 1ms 0ms
P4 4ms 0ms 1ms 1ms
At time = 20,
Process P4 will execute at the end.
Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
20-21ms P4 4ms 1ms 1ms 0ms
At time = 22,
Process P4 will finish its execution.
The overall execution of the processes will be as shown below
Time
Instance Process
Arrival
Time
Waiting
Table
Execution
Time
Initial
Burst
Time
Remaining
Burst
Time
1-2ms P1 1ms 1ms 2ms 1ms
2-3ms
P1 1ms
P1
0ms 1ms 1ms
P2 2ms 1ms 4ms 3ms
3-4ms P1 1ms P1, P2 0ms 1ms 1ms
51. Note: CPU will be idle for 0 to 1 unit time since there is no process available in
the given interval.
Gantt chart will be as following below:
Since, completion time (C.T) can be directly determined by Gantt chart, and
Turn Around Time (TAT)
= (Completion Time) – (Arrival Time)
Also, Waiting Time (WT)
= (Turn Around Time) – (Burst Time)
Therefore, final table look like,
Total Turn Around Time = 68 ms
So, Average Turn Around Time = 68/4 = 17.00 ms
And, Total Waiting Time = 48 ms
So Average Waiting Time = 48/4 = 12.00 ms
Example-2: Consider the following table of arrival time and burst time for four
processes P1, P2, P3,P4 and P5.
Processes Arrival Time Burst Time
P1 0ms 2ms
P2 0ms 3ms
P3 2ms 2ms
52. Processes Arrival Time Burst Time
P4 3ms 5ms
P5 4ms 4ms
Similarly example-1, Gantt chart for this example,
Since, completion time (CT) can be directly determined by Gantt chart, and
Turn Around Time (TAT)
= (Completion Time) – (Arrival Time)
Also, Waiting Time (WT)
= (Turn Around Time) – (Burst Time)
Therefore, final table look like,
Total Turn Around Time = 61 ms
So, Average Turn Around Time = 61/5 = 12.20 ms
And, Total Waiting Time = 45 ms
So, Average Waiting Time = 45/5 = 9.00 ms
"GeeksforGeeks helped me ace the GATE exam! Whenever I had any doubt
regarding any topic, GFG always helped me and made my concepts quiet clear." -
Anshika Modi | AIR 21
Choose GeeksforGeeks as your perfect GATE 2025 Preparation partner with
53. these newly launched programs
GATE CS & IT
GATE DS & AI
GATE Offline (Delhi/NCR)
Over 125,000+ students already trust us to be their GATE Exam guide. Join them
& let us help you in opening the GATE to top-tech IITs & NITs!
54. Program for Round Robin Scheduling for the
same Arrival time
Last Updated : 06 Dec, 2023
Round Robin is a CPU scheduling algorithm where each process is cyclically
assigned a fixed time slot. It is the preemptive version of the First come First Serve
CPU Scheduling algorithm.
Round Robin CPU Algorithm generally focuses on Time Sharing technique.
The period of time for which a process or job is allowed to run in a pre-
emptive method is called time quantum.
Each process or job present in the ready queue is assigned the CPU for that
time quantum, if the execution of the process is completed during that time
then the process will end else the process will go back to the waiting
table and wait for its next turn to complete the execution.
Characteristics of Round Robin CPU Scheduling Algorithm
It is simple, easy to implement, and starvation-free as all processes get a fair
share of CPU.
One of the most commonly used techniques in CPU scheduling is a core.
It is preemptive as processes are assigned CPU only for a fixed slice of time at
most.
The disadvantage of it is more overhead of context switching.
Advantages of Round Robin CPU Scheduling Algorithm
There is fairness since every process gets an equal share of the CPU.
The newly created process is added to the end of the ready queue.
A round-robin scheduler generally employs time-sharing, giving each job a
time slot or quantum.
While performing a round-robin scheduling, a particular time quantum is
allotted to different jobs.
Each process get a chance to reschedule after a particular quantum time in
this scheduling.
Disadvantages of Round Robin CPU Scheduling Algorithm
There is Larger waiting time and Response time.
There is Low throughput.
There is Context Switches.
Gantt chart seems to come too big (if quantum time is less for scheduling. For
Example:1 ms for big scheduling.)
Time consuming scheduling for small quantum.
55. Examples to show working of Round Robin Scheduling Algorithm
Example-1: Consider the following table of arrival time and burst time for four
processes P1, P2, P3, and P4 and given Time Quantum = 2
Process Burst Time Arrival Time
P1 5 ms 0 ms
P2 4 ms 1 ms
P3 2 ms 2 ms
P4 1 ms 4 ms
The Round Robin CPU Scheduling Algorithm will work on the basis of steps as
mentioned below:
At time = 0,
The execution begins with process P1, which has burst time 5.
Here, every process executes for 2 milliseconds (Time Quantum Period). P2
and P3 are still in the waiting queue.
Time
Instanc
e
Proces
s
Arriva
l Time
Ready
Queu
e
Runnin
g
Queue
Executio
n Time
Initia
l
Burst
Time
Remainin
g Burst
Time
0-2ms P1 0ms P2, P3 P1 2ms 5ms 3ms
At time = 2,
The processes P1 and P3 arrives in the ready queue and P2 starts executing
for TQ period
56. Time
Instanc
e
Proces
s
Arriva
l Time
Ready
Queu
e
Runnin
g
Queue
Executio
n Time
Initia
l
Burst
Time
Remainin
g Burst
Time
2-4ms
P1 0ms
P3, P1 P2
0ms 3ms 3ms
P2 1ms 2ms 4ms 2ms
At time = 4,
The process P4 arrives in the ready queue,
Then P3 executes for TQ period.
Time
Instanc
e
Proces
s
Arriva
l Time
Ready
Queu
e
Runnin
g
Queue
Executio
n Time
Initia
l
Burst
Time
Remainin
g Burst
Time
4-6ms
P1 0ms
P1, P4,
P2
P3
0ms 3ms 3ms
P2 1ms 0ms 2ms 2ms
P3 2ms 2ms 2ms 0ms
At time = 6,
Process P3 completes its execution
Process P1 starts executing for TQ period as it is next in the b.
57. Time
Instanc
e
Proces
s
Arriva
l Time
Ready
Queu
e
Runnin
g
Queue
Executio
n Time
Initia
l
Burst
Time
Remainin
g Burst
Time
6-8ms
P1 0ms
P4, P2 P1
2ms 3ms 1ms
P2 1ms 0ms 2ms 2ms
At time = 8,
Process P4 starts executing, it will not execute for Time Quantum period as
it has burst time = 1
Hence, it will execute for only 1ms.
Time
Instanc
e
Proces
s
Arriva
l Time
Ready
Queu
e
Runnin
g
Queue
Executio
n Time
Initia
l
Burst
Time
Remainin
g Burst
Time
8-9ms
P1 0ms
P2, P1 P4
0ms 3ms 1ms
P2 1ms 0ms 2ms 2ms
P4 4ms 1ms 1ms 0ms
At time = 9,
Process P4 completes its execution
Process P2 starts executing for TQ period as it is next in the ready queue
58. Time
Instanc
e
Proces
s
Arriva
l Time
Ready
Queu
e
Runnin
g
Queue
Executio
n Time
Initia
l
Burst
Time
Remainin
g Burst
Time
9-11ms
P1 0ms
P1 P2
0ms 3ms 1ms
P2 1ms 2ms 2ms 0ms
At time = 11,
Process P2 completes its execution.
Process P1 starts executing, it will execute for 1ms only
Time
Instanc
e
Proces
s
Arriva
l Time
Ready
Queu
e
Runnin
g
Queue
Executio
n Time
Initia
l
Burst
Time
Remainin
g Burst
Time
11-
12ms
P1 0ms P1 1ms 1ms 0ms
At time = 12,
Process P1 completes its execution.
The overall execution of the processes will be as shown below:
Time
Instanc
e
Proces
s
Arriva
l Time
Ready
Queu
e
Runnin
g
Queue
Executio
n Time
Initia
l
Burst
Time
Remainin
g Burst
Time
0-2ms P1 0ms P2, P3 P1 2ms 5ms 3ms
2-4ms P1 0ms P3, P1 P2 0ms 3ms 3ms
60. Time
Instanc
e
Proces
s
Arriva
l Time
Ready
Queu
e
Runnin
g
Queue
Executio
n Time
Initia
l
Burst
Time
Remainin
g Burst
Time
11-
12ms
P1 0ms P1 1ms 1ms 0ms
Gantt chart will be as following below:
Gantt chart for Round Robin Scheduling Algorithm
How to compute below times in Round Robin using a program?
Completion Time: Time at which process completes its execution.
Turn Around Time: Time Difference between completion time and arrival
time. Turn Around Time = Completion Time – Arrival Time
Waiting Time(W.T): Time Difference between turn around time and burst
time.
Waiting Time = Turn Around Time – Burst Time
Now, lets calculate average waiting time and turn around time:
Processes AT BT CT TAT WT
P1 0 5 12 12-0 = 12 12-5 = 7
P2 1 4 11 11-1 = 10 10-4 = 6
P3 2 2 6 6-2 = 4 4-2 = 2
P4 4 1 9 9-4 = 5 5-1 = 4
Now,
Average Turn around time = (12 + 10 + 4 + 5)/4 = 31/4 = 7.7
61. Average waiting time = (7 + 6 + 2 + 4)/4 = 19/4 = 4.7
Example 2: Consider the following table of arrival time and burst time for three
processes P1, P2 and P3 and given Time Quantum = 2
Process Burst Time Arrival Time
P1 10 ms 0 ms
P2 5 ms 0 ms
P3 8 ms 0 ms
Similarly, Gantt chart for this example:
Gantt chart for example 2
Now, lets calculate average waiting time and turn around time:
Processes AT BT CT TAT WT
P1 0 10 23 23-0 = 23 23-10 = 13
P2 0 5 15 15-0 = 15 15-5 = 10
P3 0 8 21 21-0 = 21 21-8 = 13
Total Turn Around Time = 59 ms
So, Average Turn Around Time = 59/3 = 19.667 ms
And, Total Waiting Time = 36 ms
So, Average Waiting Time = 36/3 = 12.00 ms
Program for Round Robin Scheduling with arrival time as 0 for all processes
Steps to find waiting times of all processes
Create an array rem_bt[] to keep track of remaining burst time of processes.
This array is initially a copy of bt[] (burst times array)
62. Create another array wt[] to store waiting times of processes. Initialize this
array as 0.
Initialize time : t = 0
Keep traversing all the processes while they are not done. Do following
for i’th process if it is not done yet.
If rem_bt[i] > quantum
t = t + quantum
rem_bt[i] -= quantum;
Else // Last cycle for this process
t = t + rem_bt[i];
wt[i] = t – bt[i]
rem_bt[i] = 0; // This process is over
Once we have waiting times, we can compute turn around time tat[i] of a process
as sum of waiting and burst times, i.e., wt[i] + bt[i].
Below is implementation of above steps.