Priority CPU Scheduling Notes | EduRev

Operating System

GATE : Priority CPU Scheduling Notes | EduRev

The document Priority CPU Scheduling Notes | EduRev is a part of the GATE Course Operating System.
All you need of GATE at this link: GATE

Program for Preemptive Priority CPU Scheduling

Implementing priority CPU scheduling. In this problem, we are using Min Heap as the data structure for implementing priority scheduling.
In this problem smaller numbers denote higher priority.
The following functions are used in the given code below:
struct process {
   processID,
   burst time,
   response time,
   priority,
   arrival time.

  • void quicksort(process array[], low, high): This function is used to arrange the processes in ascending order according to their arrival time.
  • int partition(process array[], int low, int high): This function is used to partition the array for sorting.
  • void insert(process Heap[], process value, int *heapsize, int *currentTime): It is used to include all the valid and eligible processes in the heap for execution. heapsize defines the number of processes in execution depending on the current time currentTime keeps record of the current CPU time.
  • void order(process Heap[], int *heapsize, int start): It is used to reorder the heap according to priority if the processes after insertion of new process.
  • void extractminimum(process Heap[], int *heapsize, int *currentTime): This function is used to find the process with highest priority from the heap. It also reorders the heap after extracting the highest priority process.
  • void scheduling(process Heap[], process array[], int n, int *heapsize, int *currentTime): This function is responsible for executing the highest priority extracted from Heap[].
  • void process(process array[], int n): This function is responsible for managing the entire execution of the processes as they arrive in the CPU according to their arrival time.

Priority CPU 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 process get executed.

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.
    Priority CPU Scheduling Notes | EduRev

Gantt Chart

Priority CPU Scheduling Notes | EduRev

Examples
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:
Priority CPU Scheduling Notes | EduRev

Average Wating Time is: 5.0
Average Trun Around time is: 8.2

Offer running on EduRev: Apply code STAYHOME200 to get INR 200 off on our premium plan EduRev Infinity!

Related Searches

MCQs

,

past year papers

,

Priority CPU Scheduling Notes | EduRev

,

Objective type Questions

,

video lectures

,

Important questions

,

Priority CPU Scheduling Notes | EduRev

,

Viva Questions

,

Priority CPU Scheduling Notes | EduRev

,

Semester Notes

,

ppt

,

Free

,

practice quizzes

,

Extra Questions

,

shortcuts and tricks

,

Summary

,

Sample Paper

,

study material

,

Previous Year Questions with Solutions

,

Exam

,

mock tests for examination

,

pdf

;