The Wayback Machine - https://web.archive.org/web/20240816172747/https://www.geeksforgeeks.org/priority-cpu-scheduling-with-different-arrival-time-set-2/
Open In App

Priority CPU Scheduling with different arrival time – Set 2

Last Updated : 17 Apr, 2024
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Prerequisite – Program for Priority Scheduling – Set 1
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. First process will schedule, which have the lowest arrival time, if two or more processes will have lowest arrival time, then whoever has higher priority will schedule first.
  3. Now further processes will be schedule according to the arrival time and priority of the process. (Here we are assuming that lower the priority number having higher priority). If two process priority are same then sort according to process number.
    Note: In the question, They will clearly mention, which number will have higher priority and which number will have lower priority.
  4. Once all the processes have been arrived, we can schedule them based on their priority.

Gantt Chart – 

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 :
Process_no arrival_time Burst_time Complete_time Turn_Around_Time Waiting_Time
1 0 3 3 3 0
2 1 6 9 8 2
3 3 1 16 13 12
4 2 2 11 9 7
5 4 4 15 11 7
Average Waiting Time is : 5.6
Average Turn Around time is : 8.8
C++
// C++ implementation for Priority Scheduling with 
//Different Arrival Time priority scheduling
/*1. sort the processes according to arrival time 
2. if arrival time is same the acc to priority
3. apply fcfs
*/

#include <bits/stdc++.h>

using namespace std;

#define totalprocess 5

// Making a struct to hold the given input 

struct process
{
int at,bt,pr,pno;
};

process proc[50];

/*
Writing comparator function to sort according to priority if 
arrival time is same 
*/

bool comp(process a,process b)
{
if(a.at == b.at)
{
return a.pr<b.pr;
}
else
{
    return a.at<b.at;
}
}

// Using FCFS Algorithm to find Waiting time
void get_wt_time(int wt[])
{
// declaring service array that stores cumulative burst time 
int service[50];

// Initialising initial elements of the arrays
service[0] = proc[0].at;
wt[0]=0;


for(int i=1;i<totalprocess;i++)
{
service[i]=proc[i-1].bt+service[i-1];

wt[i]=service[i]-proc[i].at;

// If waiting time is negative, change it into zero
    
    if(wt[i]<0)
    {
    wt[i]=0;
    }
}

}

void get_tat_time(int tat[],int wt[])
{
// Filling turnaroundtime array

for(int i=0;i<totalprocess;i++)
{
    tat[i]=proc[i].bt+wt[i];
}
    
}

void findgc()
{
//Declare waiting time and turnaround time array
int wt[50],tat[50];

double wavg=0,tavg=0;

// Function call to find waiting time array
get_wt_time(wt);
//Function call to find turnaround time
get_tat_time(tat,wt);
    
int stime[50],ctime[50];

stime[0] = proc[0].at;
ctime[0]=stime[0]+tat[0];

// calculating starting and ending time
for(int i=1;i<totalprocess;i++)
    {
        stime[i]=ctime[i-1];
        ctime[i]=stime[i]+tat[i]-wt[i];
    }
    
cout<<"Process_no\tStart_time\tComplete_time\tTurn_Around_Time\tWaiting_Time"<<endl;
    
    // display the process details
    
for(int i=0;i<totalprocess;i++)
    {
        wavg += wt[i];
        tavg += tat[i];
        
        cout<<proc[i].pno<<"\t\t"<<
            stime[i]<<"\t\t"<<ctime[i]<<"\t\t"<<
            tat[i]<<"\t\t\t"<<wt[i]<<endl;
    }
    
        // display the average waiting time
        //and average turn around time
    
    cout<<"Average waiting time is : ";
    cout<<wavg/(float)totalprocess<<endl;
    cout<<"average turnaround time : ";
    cout<<tavg/(float)totalprocess<<endl;

}

int main()
{
int arrivaltime[] = { 1, 2, 3, 4, 5 };
int bursttime[] = { 3, 5, 1, 7, 4 };
int priority[] = { 3, 4, 1, 7, 8 };
    
for(int i=0;i<totalprocess;i++)
{
    proc[i].at=arrivaltime[i];
    proc[i].bt=bursttime[i];
    proc[i].pr=priority[i];
    proc[i].pno=i+1;
    } 
    
    //Using inbuilt sort function
    
    sort(proc,proc+totalprocess,comp);
    
    //Calling function findgc for finding Gantt Chart
    
    findgc(); 

    return 0;
}

// This code is contributed by Anukul Chand.
Java
import java.util.*;

class Process {
    int at, bt, pr, pno;

    Process(int pno, int at, int bt, int pr) {
        this.pno = pno;
        this.pr = pr;
        this.at = at;
        this.bt = bt;
    }
}

public class PriorityScheduling {
    static final int totalprocess = 5;
    static Process proc[] = new Process[totalprocess];

    static boolean comp(Process a, Process b) {
        if (a.at == b.at) {
            return a.pr < b.pr;
        } else {
            return a.at < b.at;
        }
    }

    static void get_wt_time(int wt[]) {
        int service[] = new int[totalprocess];
        service[0] = proc[0].at;
        wt[0] = 0;

        for (int i = 1; i < totalprocess; i++) {
            service[i] = proc[i - 1].bt + service[i - 1];
            wt[i] = service[i] - proc[i].at;
            if (wt[i] < 0) {
                wt[i] = 0;
            }
        }
    }

    static void get_tat_time(int tat[], int wt[]) {
        for (int i = 0; i < totalprocess; i++) {
            tat[i] = proc[i].bt + wt[i];
        }
    }

    static void findgc() {
        int wt[] = new int[totalprocess];
        int tat[] = new int[totalprocess];
        double wavg = 0, tavg = 0;

        get_wt_time(wt);
        get_tat_time(tat, wt);

        int stime[] = new int[totalprocess];
        int ctime[] = new int[totalprocess];

        stime[0] = proc[0].at;
        ctime[0] = stime[0] + tat[0];

        for (int i = 1; i < totalprocess; i++) {
            stime[i] = ctime[i - 1];
            ctime[i] = stime[i] + tat[i] - wt[i];
        }

        System.out.println("Process_no\tStart_time\tComplete_time\tTurn_Around_Time\tWaiting_Time");

        for (int i = 0; i < totalprocess; i++) {
            wavg += wt[i];
            tavg += tat[i];

            System.out.println(proc[i].pno + "\t\t" + stime[i] + "\t\t" + ctime[i] + "\t\t" + tat[i] + "\t\t\t" + wt[i]);
        }

        System.out.println("Average waiting time is : " + wavg / totalprocess);
        System.out.println("Average turnaround time : " + tavg / totalprocess);
    }

    public static void main(String[] args) {
        int arrivaltime[] = {1, 2, 3, 4, 5};
        int bursttime[] = {3, 5, 1, 7, 4};
        int priority[] = {3, 4, 1, 7, 8};

        for (int i = 0; i < totalprocess; i++) {
            proc[i] = new Process(i + 1, arrivaltime[i], bursttime[i], priority[i]);
        }

        Arrays.sort(proc, (a, b) -> {
            if (a.at == b.at) {
                return a.pr - b.pr;
            } else {
                return a.at - b.at;
            }
        });

        findgc();
    }
}
Python3
# Python3 implementation for Priority Scheduling with 
# Different Arrival Time priority scheduling 
"""1. sort the processes according to arrival time 
   2. if arrival time is same the acc to priority 
   3. apply fcfs """
 
totalprocess = 5
proc = []
for i in range(5):
    l = []
    for j in range(4):
        l.append(0)
    proc.append(l)

# Using FCFS Algorithm to find Waiting time 
def get_wt_time( wt): 

    # declaring service array that stores
    # cumulative burst time 
    service = [0] * 5

    # Initialising initial elements 
    # of the arrays 
    service[0] = 0
    wt[0] = 0

    for i in range(1, totalprocess): 
        service[i] = proc[i - 1][1] + service[i - 1] 
        wt[i] = service[i] - proc[i][0] + 1

        # If waiting time is negative,
        # change it o zero 
        if(wt[i] < 0) :     
            wt[i] = 0
        
def get_tat_time(tat, wt): 

    # Filling turnaroundtime array 
    for i in range(totalprocess):
        tat[i] = proc[i][1] + wt[i] 

def findgc():
    
    # Declare waiting time and
    # turnaround time array 
    wt = [0] * 5
    tat = [0] * 5

    wavg = 0
    tavg = 0

    # Function call to find waiting time array 
    get_wt_time(wt) 
    
    # Function call to find turnaround time 
    get_tat_time(tat, wt) 

    stime = [0] * 5
    ctime = [0] * 5
    stime[0] = 1
    ctime[0] = stime[0] + tat[0]
    
    # calculating starting and ending time 
    for i in range(1, totalprocess): 
        stime[i] = ctime[i - 1] 
        ctime[i] = stime[i] + tat[i] - wt[i] 

    print("Process_no\tStart_time\tComplete_time",
               "\tTurn_Around_Time\tWaiting_Time")

    # display the process details 
    for i in range(totalprocess):
        wavg += wt[i] 
        tavg += tat[i] 
        
        print(proc[i][3], "\t\t", stime[i], 
                         "\t\t", end = " ")
        print(ctime[i], "\t\t", tat[i], "\t\t\t", wt[i]) 


    # display the average waiting time 
    # and average turn around time 
    print("Average waiting time is : ", end = " ")
    print(wavg / totalprocess)
    print("average turnaround time : " , end = " ")
    print(tavg / totalprocess)

# Driver code 
if __name__ =="__main__":
    arrivaltime = [1, 2, 3, 4, 5]
    bursttime = [3, 5, 1, 7, 4]
    priority = [3, 4, 1, 7, 8] 
    
    for i in range(totalprocess): 

        proc[i][0] = arrivaltime[i] 
        proc[i][1] = bursttime[i] 
        proc[i][2] = priority[i] 
        proc[i][3] = i + 1
    
    # Using inbuilt sort function 
    proc = sorted (proc, key = lambda x:x[2])
    proc = sorted (proc)
    
    # Calling function findgc for
    # finding Gantt Chart 
    findgc() 

# This code is contributed by
# Shubham Singh(SHUBHAMSINGH10)
C#
// C# implementation for Priority Scheduling with 
// Different Arrival Time priority scheduling 
// 1. sort the processes according to arrival time 
// 2. if arrival time is same the acc to priority 
// 3. apply fcfs
using System;

class Program
{
    static int totalprocess = 5;
    static int[][] proc = new int[totalprocess][];
    static int[] arrivaltime = new int[] {1, 2, 3, 4, 5};
    static int[] bursttime = new int[] {3, 5, 1, 7, 4};
    static int[] priority = new int[] {3, 4, 1, 7, 8};


    // Driver code
    static void Main(string[] args)
    {
        for (int i = 0; i < totalprocess; i++)
        {
            proc[i] = new int[4];
            proc[i][0] = arrivaltime[i];
            proc[i][1] = bursttime[i];
            proc[i][2] = priority[i];
            proc[i][3] = i + 1;
        }

        Array.Sort(proc, (x, y) => x[2].CompareTo(y[2]));
        Array.Sort(proc, (x, y) => x[0].CompareTo(y[0]));
        Findgc();
    }
    
    // Using FCFS Algorithm to find Waiting time 
    static void GetWtTime(int[] wt)
    {
        
        // declaring service array that stores
        // cumulative burst time 
        int[] service = new int[totalprocess];
        
        // Initialising initial elements 
        // of the arrays
        service[0] = 0;
        wt[0] = 0;

        for (int i = 1; i < totalprocess; i++)
        {
            service[i] = proc[i - 1][1] + service[i - 1];
            wt[i] = service[i] - proc[i][0] + 1;

            // If waiting time is negative,
            // change it o zero 
            if (wt[i] < 0)
            {
                wt[i] = 0;
            }
        }
    }

    // Filling turnaroundtime array
    static void GetTatTime(int[] tat, int[] wt)
    {
        for (int i = 0; i < totalprocess; i++)
        {
            tat[i] = proc[i][1] + wt[i];
        }
    }

    static void Findgc()
    {
        
        // Declare waiting time and
        // turnaround time array 
        int[] wt = new int[totalprocess];
        int[] tat = new int[totalprocess];
        int wavg = 0;
        int tavg = 0;
        
         // Function call to find waiting time array 
        GetWtTime(wt);
        
        // Function call to find turnaround time
        GetTatTime(tat, wt);
        int[] stime = new int[totalprocess];
        int[] ctime = new int[totalprocess];
        stime[0] = 1;
        ctime[0] = stime[0] + tat[0];

        Console.WriteLine("Process_no\tStart_time\tComplete_time\tTurn_Around_Time\tWaiting_Time");

        // calculating starting and ending time
        for (int i = 0; i < totalprocess; i++)
        {
            wavg += wt[i];
            tavg += tat[i];
            Console.WriteLine(proc[i][3] + "\t\t" + stime[i] + "\t\t" + ctime[i] + "\t\t" + tat[i] + "\t\t\t" + wt[i]);
            
            
            // display the process details
            if (i != totalprocess - 1)
            {
                stime[i + 1] = ctime[i];
                ctime[i + 1] = stime[i + 1] + tat[i + 1] - wt[i + 1];
            }
        }

        // display the average waiting time 
        // and average turn around time
        Console.WriteLine("Average waiting time is: " + (double)wavg / totalprocess);
        Console.WriteLine("Average turnaround time is: " + (double)tavg / totalprocess);
    }
}

// This code is contributed by shiv1o43g
JavaScript
var totalprocess = 5;
var proc = [];
for (var i = 0; i < 5; i++) {
    var l = [];
    for (var j = 0; j < 4; j++) {
        l.push(0);
    }
    proc.push(l);
}

function get_wt_time(wt) {
    var service = new Array(5).fill(0);
    service[0] = 0;
    wt[0] = 0;
    for (var i = 1; i < totalprocess; i++) {
        service[i] = proc[i - 1][1] + service[i - 1];
        wt[i] = service[i] - proc[i][0] + 1;
        if (wt[i] < 0) {
            wt[i] = 0;
        }
    }
}

function get_tat_time(tat, wt) {
    for (var i = 0; i < totalprocess; i++) {
        tat[i] = proc[i][1] + wt[i];
    }
}

function findgc() {
    var wt = new Array(5).fill(0);
    var tat = new Array(5).fill(0);
    var wavg = 0;
    var tavg = 0;
    get_wt_time(wt);
    get_tat_time(tat, wt);
    var stime = new Array(5).fill(0);
    var ctime = new Array(5).fill(0);
    stime[0] = 1;
    ctime[0] = stime[0] + tat[0];
    for (var i = 1; i < totalprocess; i++) {
        stime[i] = ctime[i - 1];
        ctime[i] = stime[i] + tat[i] - wt[i];
    }
    console.log("Process_no\tStart_time\tComplete_time\tTurn_Around_Time\tWaiting_Time"
    );
    for (var i = 0; i < totalprocess; i++) {
        wavg += wt[i];
        tavg += tat[i];
        console.log(
        proc[i][3] +
        "\t\t" +
        stime[i] +
        "\t\t" +
        ctime[i] +
        "\t\t" +
        tat[i] +
        "\t\t\t" +
        wt[i]
        );
    }
    console.log("Average waiting time is : " + wavg / totalprocess);
    console.log("average turnaround time : " + tavg / totalprocess);
}

var arrivaltime = [1, 2, 3, 4, 5];
var bursttime = [3, 5, 1, 7, 4];
var priority = [3, 4, 1, 7, 8];
for (var i = 0; i < totalprocess; i++) {
    proc[i][0] = arrivaltime[i];
    proc[i][1] = bursttime[i];
    proc[i][2] = priority[i];
    proc[i][3] = i + 1;
}

proc.sort(function (a, b) {
    if (a[2] == b[2]) {
    return a[0] - b[0];
    } else {
    return a[2] - b[2];
    }
});
findgc();

// This code is contributed by shiv1o43g

Output: 

Process_no Start_time Complete_time Turn_Around_Time Waiting_Time
1 1 4 3 0
2 5 10 8 3
3 4 5 2 1
4 10 17 13 6
5 17 21 16 12
Average Waiting Time is : 4.4
Average Turn Around time is : 8.4

Time Complexity: O(N * logN), where N is the total number of processes. 
Auxiliary Space: O(N) 


 



Similar Reads

Difference between Arrival Time and Burst Time in CPU Scheduling
CPU scheduling algorithms require CPU time and IO time required for its execution. CPU time is time taken by CPU to carry out the process while I/O time illustrates the time required for I/O operation by the process. The execution of multiple processes in an optimised way is based on different kinds of algorithms, like FCFS, Shortest Job First etc.
3 min read
Program for FCFS CPU Scheduling | Set 2 (Processes with different arrival times)
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 queu
15+ min read
Difference between Preemptive Priority based and Non-preemptive Priority based CPU scheduling algorithms
Prerequisite - CPU Scheduling Priority Scheduling : In priority scheduling, each process has a priority which is an integer value assigned to it. The smallest integer is considered as the highest priority and the largest integer is considered as the lowest priority. The process with the highest priority gets the CPU first. In rare systems, the larg
4 min read
Difference between Priority Scheduling and Round Robin (RR) CPU scheduling
1. Priority Scheduling Algorithm : Priority scheduling algorithm executes the processes depending upon their priority. Each process is allocated a priority and the process with the highest priority is executed first. Priorities can be defined internally as well as externally. Internal priorities are decided by the system depending upon the number o
3 min read
Difference between Priority scheduling and Shortest Job First (SJF) CPU scheduling
1. Priority Scheduling Algorithm : Priority scheduling algorithm executes the processes depending upon their priority. Each process is allocated a priority and the process with the highest priority is executed first. Priorities can be defined internally as well as externally. Internal priorities are decided by the system depending upon the number o
3 min read
Program for Round Robin Scheduling for the same Arrival time
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
15+ min read
Program for Priority CPU Scheduling | Set 1
Priority scheduling is one of the most common scheduling algorithms in batch systems. Each process is assigned a priority. The process with the highest priority is to be executed first and so on. Processes with the same priority are executed on a first-come first served basis. Priority can be decided based on memory requirements, time requirements
11 min read
Difference Between User-CPU-Time and System-CPU-Time in UNIX
Unix systems have a time utility that allows a user to see where their application took significant time to process. The syntax of this utility is as follows: time &lt;command-to-be-timed&gt;Its result generally has three categories as follows: real &lt;time&gt; user &lt;time&gt; sys &lt;time&gt;User CPU time and system CPU time are both measures o
3 min read
Difference between FCFS and Priority CPU scheduling
1. First Come First Served (FCFS) : First Come First Served (FCFS) is the simplest type of algorithm. It is a non-preemptive algorithm i.e. the process cannot be interrupted once it starts executing. The FCFS is implemented with the help of a FIFO queue. The processes are put into the ready queue in the order of their arrival time. The process that
3 min read
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(proc
15+ min read
Preemptive Priority CPU Scheduling Algorithm
Preemptive Priority CPU Scheduling Algorithm is a pre-emptive method of CPU scheduling algorithm that works based on the priority of a process. In this algorithm, the scheduler schedules the tasks to work as per the priority, which means that a higher priority process should be executed first. In case of any conflict, i.e., when there is more than
15+ min read
Multilevel Feedback Queue Scheduling (MLFQ) CPU Scheduling
Multilevel Feedback Queue Scheduling (MLFQ) CPU Scheduling is like Multilevel Queue(MLQ) Scheduling but in this process can move between the queues. And thus, much more efficient than multilevel queue scheduling. Characteristics of Multilevel Feedback Queue Scheduling: In a multilevel queue-scheduling algorithm, processes are permanently assigned t
5 min read
Difference between Turn Around Time (TAT) and Waiting Time (WT) in CPU Scheduling
In CPU Scheduling, we often need to find the average Turnaround and Waiting Time with the help of Arrival, Burst and Completion Time. Let's have a brief look of them: Turnaround Time (TAT): It is the time interval from the time of submission of a process to the time of the completion of the process.The difference b/w Completion Time and Arrival Tim
2 min read
Difference between Multi Level Queue Scheduling (MLQ) and Priority Scheduling
1. Multi Level Queue Scheduling (MLQ) : It is quite difficult to have just one queue and schedule all processes. This is where multi-level queue scheduling is used. In this, processes are divided into various classes depending upon property of processes such as system process, I/O process, etc. Thus we get 'n' number of queues for n classes of proc
3 min read
Comparison of Different CPU Scheduling Algorithms in OS
A scheduling algorithm is used to estimate the CPU time required to allocate to the processes and threads. The prime goal of any CPU scheduling algorithm is to keep the CPU as busy as possible for improving CPU utilization. Scheduling Algorithms 1. First Come First Serve(FCFS): As the name implies that the jobs are executed on a first come first se
5 min read
Longest Remaining Time First (LRTF) CPU Scheduling Program
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 algo
15+ min read
Time Slicing in CPU scheduling
CPUs kernel doesn't simply distribute the entirety of our PCs' resources to single process or service. CPU is continuously running many processes that are essential for it to operate, so our kernel needs to manage these processes without moment's delay. When program needs to run, process must be created for it. This process needs to have important
3 min read
Shortest Job First CPU Scheduling with Predicted Burst Time
Shortest Job First (SJF) is an optimal scheduling algorithm as it gives maximum Throughput and minimum average waiting time(WT) and turnaround time (TAT) but it is not practically implementable because the burst time of a process can't be predicted in advance. We may not know the length of the next CPU burst, but we may be able to predict its value
5 min read
Longest Remaining Time First (LRTF) or Preemptive Longest Job First CPU Scheduling Algorithm
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
7 min read
Priority to Round-robin scheduling with dynamic time quantum
Prerequisite - Program for Round Robin scheduling Processes are executed on basis of their priority in this scheduling algorithm. Processes have a specific priority associated with them on arrival. When a process arrives its priority is compared with other processes in the ready queue and if its priority is higher then it becomes running process. I
2 min read
Scheduling priority tasks in limited time and minimizing loss
Given n tasks with arrival time, priority and number of time units they need. We need to schedule these tasks on a single resource. The objective is to arrange tasks such that maximum priority tasks are taken. Objective is to minimize sum of product of priority and left time of tasks that are not scheduled due to limited time. This criteria simply
11 min read
Program for Shortest Job First (or SJF) CPU Scheduling | Set 1 (Non- preemptive)
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
13 min read
Program for FCFS CPU Scheduling | Set 1
First come - First served (FCFS), is the simplest scheduling algorithm. FIFO simply queues processes according to the order they arrive in the ready queue. In this algorithm, the process that comes first will be executed first and next process starts only after the previous gets fully executed.  Terminologies Used in CPU Scheduling Arrival Time: Th
15+ min read
Difference between Priority Inversion and Priority Inheritance
Both of these concepts come under Priority scheduling in Operating System. But are they the same? In one line, Priority Inversion is a problem while Priority Inheritance is a solution. Priority Inversion means that the priority of tasks gets inverted and Priority Inheritance means that the priority of tasks gets inherited. Both of these phenomena h
2 min read
Should we declare as Queue or Priority Queue while using Priority Queue in Java?
Queue: Queue is an Interface that extends the collection Interface in Java and this interface belongs to java.util package. A queue is a type of data structure that follows the FIFO (first-in-first-out ) order. The queue contains ordered elements where insertion and deletion of elements are done at different ends. Priority Queue and Linked List are
3 min read
What is Priority Queue | Introduction to Priority Queue
A priority queue is a type of queue that arranges elements based on their priority values. Elements with higher priority values are typically retrieved or removed before elements with lower priority values. Each element has a priority value associated with it. When we add an item, it is inserted in a position based on its priority value. There are
15+ min read
Operating Systems | CPU Scheduling | Question 1
Consider three processes (process id 0, 1, 2 respectively) with compute time bursts 2, 4 and 8 time units. All processes arrive at time zero. Consider the longest remaining time first (LRTF) scheduling algorithm. In LRTF ties are broken by giving priority to the process with the lowest process id. The average turn around time is: (A) 13 units (B) 1
1 min read
Operating Systems | CPU Scheduling | Question 2
Consider three processes, all arriving at time zero, with total execution time of 10, 20 and 30 units, respectively. Each process spends the first 20% of execution time doing I/O, the next 70% of time doing computation, and the last 10% of time doing I/O again. The operating system uses a shortest remaining compute time first scheduling algorithm a
2 min read
Advantages and Disadvantages of various CPU scheduling algorithms
CPU Scheduling involves many different scheduling algorithms which have their Advantages and Disadvantages. 1. First Come First Serve (FCFS): Advantages: It is simple and easy to understand.FCFS provides fairness by treating all processes equally and giving them an equal opportunity to run.FCFS guarantees that every process will eventually get a ch
3 min read
Difference between SJF and LJF CPU scheduling algorithms
Shortest Job First: The shortest job first (SJF) algorithm is a CPU scheduling algorithm designed to reorder the jobs so that the process having the smallest burst time is chosen for the next execution. It is used to reduce the average waiting time for other processes waiting for execution. This may be preemptive or non-preemptive. Its preemptive v
4 min read
Article Tags :
Practice Tags :
three90RightbarBannerImg