0% found this document useful (0 votes)
3 views3 pages

7th(Priority) s

The document presents a Java program that implements Priority CPU scheduling to calculate total waiting time, average waiting time, total turnaround time, average turnaround time, and a Gantt chart. It prompts the user to input the number of processes, their burst times, and priority values, and then computes the necessary metrics. The output includes detailed information about each process along with the calculated average times.

Uploaded by

malikirfan0502
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)
3 views3 pages

7th(Priority) s

The document presents a Java program that implements Priority CPU scheduling to calculate total waiting time, average waiting time, total turnaround time, average turnaround time, and a Gantt chart. It prompts the user to input the number of processes, their burst times, and priority values, and then computes the necessary metrics. The output includes detailed information about each process along with the calculated average times.

Uploaded by

malikirfan0502
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/ 3

Shahabuddin Ahmad 11232945 I

Practical-07
Aim- List of processes / jobs along with their arrival times, priority value & CPU burst times is given. Write
a program to print the total waiting time, average waiting time, total turnaround time, average turnaround
time & Gantt chart using Priority CPU scheduling policy.

Code-

import java.util.Scanner; public class


PriorityScheduling{ public static void
main(String args[]) { Scanner s = new
Scanner(System.in); int
x,n,p[],pp[],bt[],w[],t[],awt,atat,i; p =
new int[10]; pp = new int[10]; bt =
new int[10]; w = new int[10]; t = new
int[10];
System.out.print("Enter the number of process : ");
n = s.nextInt();
System.out.print("\n\t Enter burst time : time priorities \n");
for(i=0;i<n;i++)
{
System.out.print("\nProcess["+(i+1)+"]:");
bt[i] = s.nextInt(); pp[i] = s.nextInt();
p[i]=i+1;
}
for(i=0;i<n-1;i++)
{
for(int j=i+1;j<n;j++)
{
if(pp[i]>pp[j])
{
x=pp[i];
pp[i]=pp[j];
pp[j]=x; x=bt[i];
Shahabuddin Ahmad 11232945 I

bt[i]=bt[j];
bt[j]=x; x=p[i];
p[i]=p[j];
p[j]=x;
}
} } w[0]=0;
awt=0;
t[0]=bt[0];
atat=t[0];
for(i=1;i<n;i++)
{ w[i]=t[i-1];
awt+=w[i];
t[i]=w[i]+bt[i];
atat+=t[i];
}
System.out.print("\n\nProcess \t Burst Time \t Wait Time \t Turn Around Time Priority \n");
for(i=0;i<n;i++)
System.out.print("\n "+p[i]+"\t\t "+bt[i]+"\t\t "+w[i]+"\t\t "+t[i]+"\t\t "+pp[i]+"\n");
awt/=n; atat/=n;
System.out.print("\n Average Wait Time : "+awt);
System.out.print("\n Average Turn Around Time : "+atat);
}
}
Shahabuddin Ahmad 11232945 I

Output-

You might also like