0% found this document useful (0 votes)
466 views5 pages

Lab 11 - Priority Scheduling

The document discusses priority scheduling algorithms in CPU scheduling. It describes preemptive and non-preemptive priority scheduling. Preemptive priority scheduling allows higher priority tasks to preempt lower priority tasks currently running. Non-preemptive priority scheduling allocates the CPU to the highest priority ready process and does not preempt currently running processes. The document provides examples and characteristics of priority scheduling and discusses advantages and disadvantages.

Uploaded by

Gurru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
466 views5 pages

Lab 11 - Priority Scheduling

The document discusses priority scheduling algorithms in CPU scheduling. It describes preemptive and non-preemptive priority scheduling. Preemptive priority scheduling allows higher priority tasks to preempt lower priority tasks currently running. Non-preemptive priority scheduling allocates the CPU to the highest priority ready process and does not preempt currently running processes. The document provides examples and characteristics of priority scheduling and discusses advantages and disadvantages.

Uploaded by

Gurru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Lab 9- CPU Scheduling

Priority Scheduling Algorithm

Priority Scheduling is a method of scheduling processes that is based on priority.


In this algorithm, the scheduler selects the tasks to work as per the priority.

The processes with higher priority should be carried out first, whereas jobs with
equal priorities are carried out on a round-robin or FCFS basis. Priority depends
upon memory requirements, time requirements, etc.

Types of Priority Scheduling


Priority scheduling divided into two main types:

Preemptive Scheduling
In Preemptive Scheduling, the tasks are mostly assigned with their priorities.
Sometimes it is important to run a task with a higher priority before another lower
priority task, even if the lower priority task is still running. The lower priority task
holds for some time and resumes when the higher priority task finishes its
execution.

Non-Preemptive Scheduling
In this type of scheduling method, the CPU has been allocated to a specific process.
The process that keeps the CPU busy, will release the CPU either by switching
context or terminating. It is the only method that can be used for various hardware
platforms. That's because it doesn't need special hardware (for example, a timer)
like preemptive scheduling.

Characteristics of Priority Scheduling


• A CPU algorithm that schedules processes based on priority.
• It used in Operating systems for performing batch processes.
• If two jobs having the same priority are READY, it works on a FIRST COME,
FIRST SERVED basis.
• In priority scheduling, a number is assigned to each process that indicates its
priority level.
• Lower the number, higher is the priority.
• In this type of scheduling algorithm, if a newer process arrives, that is having
a higher priority than the currently running process, then the currently
running process is preempted.

Advantages of priority scheduling


Here, are benefits/pros of using priority scheduling method:

• Easy to use scheduling method


• Processes are executed on the basis of priority so high priority does not need
to wait for long which saves time
• This method provides a good mechanism where the relative important of
each process may be precisely defined.
• Suitable for applications with fluctuating time and resource requirements.

Disadvantages of priority scheduling


Here, are cons/drawbacks of priority scheduling

• If the system eventually crashes, all low priority processes get lost.
• If high priority processes take lots of CPU time, then the lower priority
processes may starve and will be postponed for an indefinite time.
• This scheduling algorithm may leave some low priority processes waiting
indefinitely.
• A process will be blocked when it is ready to run but has to wait for the CPU
because some other process is running currently.
• If a new higher priority process keeps on coming in the ready queue, then
the process which is in the waiting state may need to wait for a long duration
of time.
LAB: Part 1. NON-Preemptive Priority Scheduling:
Example:

How to compute Completion, Turn Around and Waiting time:

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 turnaround time and burst time.
Waiting Time = Turn Around Time – Burst Time

Implementation
Lab Assignment 1:
Write a general code to implement the Priority based non-preemptive CPU scheduling
algorithm. Input should be number of processes, bust time along with priority. Arrival
time is zero, and output should be as follows.

Example Output:

Order in which processes gets executed


2 1 4 3
Processes Burst time Waiting time Turn around time
2 3 0 3
1 21 3 24
4 2 24 26
3 6 26 32

Average waiting time = 13.25


Average turn around time = 61

LAB: Part 2. NON-Preemptive Priority Scheduling with different arrival


time:

Priority scheduling is a non-preemptive algorithm and one of the most common


scheduling algorithms in batch systems. Each process is assigned first arrival time (less
arrival time process first) if two processes have same arrival time, then compare to
priorities (highest process first). Also, if two processes have same priority then compare
to process number (less process number first). This process is repeated while all
processes get executed.
Example:

Implementation –
1. First input the processes with their arrival time, burst time and priority.
2. Sort the processes, according to arrival time if two process arrival time is same
then sort according process priority if two process priority are same then sort
according to process number.
3. Now simply apply FCFS algorithm.

2. Lab Assignment 2:
Write a general code to implement the Priority based non-preemptive CPU
scheduling algorithm with given arrival times. Input should be number of
processes, bust time along with priority. Output should be as follows

Output:
Input :
process no-> 1 2 3 4 5
arrival time-> 0 1 3 2 4
burst time-> 3 6 1 2 4
priority-> 3 4 9 7 8
Output :
Process_no Start_time Complete_time Trun_Around_Time Wating_Time
1 0 3 3 0
2 3 9 8 2
4 9 11 9 7
3 11 12 9 8
5 12 16 12 8
Average Wating Time is : 5.0
Average Trun Around time is : 8.2

You might also like