Lab 11 - Priority Scheduling
Lab 11 - Priority Scheduling
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.
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.
• 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:
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:
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