0% found this document useful (0 votes)
57 views1 page

Priority Scheduling Java Program

This Java code implements a shortest job first (SJF) CPU scheduling algorithm. It takes user input for the number of processes, their burst times, arrival times, and priorities. It then simulates scheduling by decrementing the burst time of the process with the shortest burst time left. It calculates turnaround times, waiting times, average times, and throughput.

Uploaded by

FaizanAhmedJafri
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)
57 views1 page

Priority Scheduling Java Program

This Java code implements a shortest job first (SJF) CPU scheduling algorithm. It takes user input for the number of processes, their burst times, arrival times, and priorities. It then simulates scheduling by decrementing the burst time of the process with the shortest burst time left. It calculates turnaround times, waiting times, average times, and throughput.

Uploaded by

FaizanAhmedJafri
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/ 1

import java.util.

*;
class OSPROJECT
{
int bt,at,process,pri,tat,wt,copy_of_bt;
static double nn;
static double bb;
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.println("enter no. of processes : ");
int n=sc.nextInt();
nn=n;
OSPROJECT op[] = new OSPROJECT[n+1];
for(int i=0;i<=n;i++){
op[i]= new OSPROJECT();}
int sum=0;
for(int m=1;m<=n;m++){
op[m].process=m;
System.out.println("enter burst time,arrival time and priority of process "+m);
op[m].bt=sc.nextInt();
op[m].at=sc.nextInt();
op[m].pri=sc.nextInt();
sum+=op[m].bt;
bb+=op[m].bt;
op[m].copy_of_bt=op[m].bt;}
for(int t=1;t<=sum+1;t++)
{
int min=9999,index=0;
for(int j=1;j<=n;j++) {
if(op[j].at<t && op[j].pri<min && op[j].bt>0) {
min=op[j].pri;
index=j;
System.out.print("P"+index+" ");
} }
op[index].bt-=1;
if(op[index].bt==0) {
op[index].tat=t-op[index].at;
op[index].wt=op[index].tat-op[index].copy_of_bt; }

int tot_turn=0,tot_wait=0;
for(int i=1;i<=n;i++) {
tot_turn+=op[i].tat;
tot_wait+=op[i].wt; }
float avg_turn=(float)tot_turn/n;
float avg_wait=(float)tot_wait/n;
for(int m=1;m<=n;m++) {
System.out.println("\nprocess "+op[m].process);
System.out.print("turn around time : "+op[m].tat);
System.out.print(" waiting time : "+op[m].wt); }
System.out.println("\ntotal turn around time : "+tot_turn);
System.out.println("total waiting time : "+tot_wait);
System.out.println("avg turn around time : "+avg_turn);
System.out.println("avg waiting time : "+avg_wait);
System.out.println("Through put:"+nn/bb);
}
}

You might also like