In this tutorial, we will be discussing What is Priority Scheduling in OS, How Priority Scheduling in OS works. What are the key points that should be noted down for the Priority Scheduling in OS. We will try to cover every concept regarding priority scheduling in OS. Let’s get started and deep dive into interesting topic i.e. Priority Scheduling in OS.
What is Priority Scheduling?
Determining the sequence in which processes and activities will access the processor and how much processing time each will receive is a key responsibility of the operating system. Process scheduling refers to this operating system feature. Process scheduling involves the tasks that the operating system performs are:
- Keeping track of the status of the processes
- Allocation of processor to processes
- De-allocation of processor to processes.
The operating system stores each of these processes in a process table and assigns each one a unique ID (PID) in order to keep track of them all. Additionally, the operating system utilises a Process Control Block (PCB) to monitor their present condition. When the process’s status changes, the information is updated in the control block.
But did you ever wonder what the Operating System’s criteria are for scheduling these processes? What process needs to be given CPU resources first? The Operating System can decide to execute the process that takes the least amount of time first, execute the processes in the order in which they requested access to the CPU, and so on. The process’s priority is one of these crucial factors.
Processes are carried out according to priority scheduling in OS. Higher-priority tasks or procedures are carried out first. Naturally, you might be interested in learning how procedures are prioritised.
Process priorities rely on a number of elements, including:
- Time limit
- Memory requirements of the process
- Ratio of average I/O to average CPU burst time
There may be more criteria used to assess the priority of a process or task. The scheduler assigns the processes this priority.
These processes’ priority are expressed as straightforward numbers with defined ranges, such 0 to 7 or perhaps 0 to 4095. These figures vary according to the kind of systems.
Now that we are aware that each task is given a priority based on its scheduling, we can go on to discussing its workings and kinds.
Types of Priority Scheduling
Priority scheduling in OS divided into two main types:
Tasks are often assigned in Preemptive Scheduling according to their priority. Even while the lower priority operation is still in progress, it is occasionally essential to run the higher priority activity first. When the higher priority activity has finished its execution, the lower priority task will pause for a while before continuing.
The CPU has been assigned to a certain process in this kind of scheduling approach. The activity that occupies the CPU will free it by changing context or ceasing. The only approach that works on a variety of hardware platforms is this one. That’s because, unlike preemptive scheduling, it doesn’t require specialised hardware (like a timer).
Characteristics of Priority Scheduling
The characteristic of priority scheduling in OS is as follows:
- A CPU algorithm that prioritises processes while scheduling them.
- Operating systems use it to carry out batch operations.
- It operates on a FIRST COME, FIRST SERVED basis if two jobs of the same priority are READY.
- Each process in priority scheduling is given a number that represents the priority level.
- The priority rises as the number falls.
- If a newer process enters the system with a higher priority than the one that is already executing, the existing process is preempted in this sort of scheduling method.
Example of Priority Scheduling Algorithm:
The fundamentals of priority scheduling in OS are now clear to you. Let’s use preemptive scheduling as an illustration to help you better comprehend.
Consider the priority, burst time, and arrival time of five processes (P1–P5). Please Google the phrases "burst" and "arrival time" if you are unfamiliar. These values connected to these procedures will be shown in a table.
|Process||Priority||Burst Time||Arrival Time|
Let’s put our knowledge of priority scheduling methods to use. Which procedure do you anticipate being carried out first? Remember: the higher the priority, the lower the number. To keep track of the progress and determine whether a procedure needs to be preempted, we’ll utilise a Gantt chart.
Therefore, P1 and P2 will be given priority for execution as they come first, i.e. at time = 0. Process P1 will be carried out first since it has a greater priority than P2 due to this.
Process P1 continues to run after time = 1 because no other processes have begun, and this continues until time = 4, at which point the process’s execution is complete.
Process P2 was waiting in line the entire time. When process P1 has finished running, we choose the subsequent process in the waiting queue based on priority, regardless of when it will arrive. The only process in the waiting line has a burst time of 3, thus we begin the execution of process P2 because there is only one process in the queue.
Process P2 is still running at time = 5 and has 2 burst minutes left. We observe that another process enters the waiting line at time = 6. First, we must determine the priority. Since P3 has a higher priority than P2, we must preempt the running process and begin P3’s execution while leaving P2 in the ready queue with one burst time left (it already executed for 2 seconds).
|Process||Priority||Burst Time||Arrival Time|
With a burst time of 7, the process P3 will clearly keep running until a process with a higher priority enters the system. At time 11, another process, P4, enters the system. However, because P4 has a lower priority than P3, P3 will continue to run with its remaining two units.
P3 will run till time equals 13. We now check the processes in our waiting queue. Keep in mind that we choose the procedures that came first and had a greater importance. We currently have procedures P2, P4, and P5 in our waiting list. While P2 and P5 appear to have similar importance, P2 must be carried out first because it arrived earlier than P5.
As we preempted the process to run P3, P2 only has one unit time remaining to process. P2 process completes its execution at time = 14. Once more, we search the waiting queue for a process that can be performed. P4 and P5 are in the line of people waiting. We begin P5’s execution because it is more important than the others.
Process P5’s burst time is 2, and as a result, it finishes running at time = 16. Process P4 is the only one still running at this point, and it begins its execution at time = 16. P4 continues and completes its execution by time = 20 since its burst time is 4, there are no more processes in the waiting queue, and no new processes with a higher priority have arrived.
Now that you know how the OS’s preemptive priority scheduling functions, congrats! Let’s go on and examine its benefits and drawbacks.
Advantages of Priority Scheduling
Following are some advantages of employing the priority scheduling method:
- Simple scheduling technique
- Processes are carried out according to priority, thus high priority tasks may be completed quickly, saving time.
- The relative relevance of each process may be accurately described using this strategy, which offers a solid mechanism for doing so.
- Appropriate for applications with varying time and resource needs.
Disadvantages of Priority Scheduling
These are the negative aspects of priority scheduling.
- Any low priority processes that are running at the time of a system crash are lost.
- Lower priority processes may starve and be delayed indefinitely if high priority processes use a lot of CPU time.
- Some low priority activities may be kept waiting for an eternity by this scheduling strategy.
- When a process is prepared to execute but must wait for the CPU because another process is already active, it will be blocked.
- The process in the waiting state may have to wait a very long period if fresh, higher priority processes keep entering the ready queue.
Static and Dynamic Priority Scheduling in OS
Did you wonder how the priorities were originally assigned to the process while we were learning about how to give processes priorities? Alternatively, when was the process given priority?
Priority based scheduling may be used in two different ways, preemptive and non-preemptive, with preemptive priority based scheduling being the most popular. It may be categorised once more in the same way based on how processes’ priorities are determined.
The two classifications are:
- Static priority
- Dynamic priority
When a process is designed using the Static Priority method, its associated priorities are determined at that moment and do not alter throughout the process’s existence. However, the dynamic priority algorithm assigns precedence to the processes during runtime based on the processes’ execution characteristics, such as approaching deadlines.
The static priority algorithms are, of course, easier to understand than the dynamic priority algorithms. For a system to function better, different scheduling algorithms such multilayer queues and multilevel feedback queues scheduling are crucial.
- The scheduling of processes according to their priority occurs in operating systems.
- This priority is determined by variables like the time allotted, the process’s memory needs, and the ratio of average I/O to average CPU burst time.
- Priority scheduling primarily comes in two flavours: non-preemptive (where another process may only be performed after the current one has finished executing) and preemptive (where a higher priority process pauses the current running process and completes its execution first).
- The fundamental drawback of priority scheduling is the possibility of famine for lower priority operations.
- Process priorities may be determined statically or dynamically.
- Additional scheduling methods include multilayer queues and multilevel feedback queues, which effectively aggregate related operations into distinct queues so they may each use a different scheduling algorithm.
So with this we came to an end of this blog, i.e. Priority Scheduling in OS. we hope we have covered your all doubts. Beside this, there is alot to cover about Operating Systems. Operating system is one of the important topics when it comes to placements. Try and push more about Operating Systems.
FAQ regarding Priority Scheduling in OS
1. What are the types of Priority Scheduling in OS?
There are two different categories of priority scheduling algorithms. Preemptive priority scheduling is one, while non-preemptive priority scheduling is the other. Each process may or may not have a different priority number assigned to it.
2. Why is it called Priority?
Prior, which implies to come before something else, is where the term priority originates. The worry, interest, or goal that takes precedence over all others is called a priority.
3. What are the major Scheduling Algorithms?
The common process scheduling methods that we will discuss in this chapter are as follows:
- First-Come, First-Served (FCFS) Scheduling.
- Shortest-Job-Next (SJN) Scheduling.
- Priority Scheduling.
- Shortest Remaining Time.
- Round Robin(RR) Scheduling.
- Multiple-Level Queues Scheduling.