0% found this document useful (0 votes)
30 views2 pages

Priority

The document describes a program that implements priority scheduling for processes. It takes the number of processes, their burst times and priorities as input. It then sorts the processes by priority and calculates their completion times, waiting times and turnaround times. It outputs the priority, process id, burst time, completion time, waiting time and turnaround time for each process, along with the average waiting time and turnaround time.

Uploaded by

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

Priority

The document describes a program that implements priority scheduling for processes. It takes the number of processes, their burst times and priorities as input. It then sorts the processes by priority and calculates their completion times, waiting times and turnaround times. It outputs the priority, process id, burst time, completion time, waiting time and turnaround time for each process, along with the average waiting time and turnaround time.

Uploaded by

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

Name:Laksh

import java.util.Scanner;

public class Priority {


public static void main(String args[])
{
Scanner sn=new Scanner(System.in);
System.out.print("Enter No of processes :");
int n=sn.nextInt();

int process[]=new int[n];


int priority[]=new int[n];
int arrival[]=new int[n];
int brust[]=new int[n];
int completion[]=new int[n];
int WT[]=new int[n];
int TAT[]=new int[n];
int sum=0;
float totalaroundtime=0,waittime=0;

for(int i=0;i<n;i++)
{
System.out.print("Enter Process "+(i+1)+"Brust Time :");
brust[i]=sn.nextInt();

System.out.print("Enter Process "+(i+1)+"Priority :");


priority[i]=sn.nextInt();

process[i]=i+1;
}

for(int i=0;i<n-1;i++)
{
for(int j=i+1;j<n;j++)
{
if(priority[i]<priority[j])
{
int temp=priority[i];
priority[i]=priority[j];
priority[j]=temp;

temp=process[i];
process[i]=process[j];
process[j]=temp;

temp=brust[i];
brust[i]=brust[j];
brust[j]=temp;

}
}

}
for(int i=0;i<n;i++)
{
sum=sum+brust[i];
completion[i]=sum;
}

System.out.print("\n\nPriority \tProcess \tBrusttime \tCompletion


\tWT \tTAT");
for(int i=0;i<n;i++)
{
TAT[i]=completion[i]-arrival[i];
totalaroundtime=totalaroundtime+TAT[i];

WT[i]=TAT[i]-brust[i];
waittime=waittime+WT[i];

System.out.print("\n"+priority[i]+"\t\t"+process[i]+"\t\
t"+brust[i]+"\t\t"+completion[i]+"\t\t"+WT[i]+"\t\t"+TAT[i]);
}
System.out.print("\n\nAvergae Turn Around Time :"+
(totalaroundtime/n));
System.out.print("\nAvergae Wait Time :"+(waittime/n));

}
}

Output:

Enter No of processes :4
Enter Process 1Brust Time :3
Enter Process 1Priority :4
Enter Process 2Brust Time :6
Enter Process 2Priority :7
Enter Process 3Brust Time :9
Enter Process 3Priority :10
Enter Process 4Brust Time :12
Enter Process 4Priority :14

Priority Process Brusttime Completion WT TAT


14 4 12 12 0 12
10 3 9 21 12 21
7 2 6 27 21 27
4 1 3 30 27 30

Avergae Turn Around Time :22.5


Avergae Wait Time :15.0

You might also like