0% found this document useful (0 votes)
53 views4 pages

Multilevel

This document describes a program that implements a multilevel queue scheduling algorithm. It takes user input for the number of processes, their names and burst times. It then simulates running the processes using priority queue, round robin and FIFO scheduling, calculating their waiting times. Finally it outputs the total and average waiting and turnaround times.

Uploaded by

akhileshchafale
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views4 pages

Multilevel

This document describes a program that implements a multilevel queue scheduling algorithm. It takes user input for the number of processes, their names and burst times. It then simulates running the processes using priority queue, round robin and FIFO scheduling, calculating their waiting times. Finally it outputs the total and average waiting and turnaround times.

Uploaded by

akhileshchafale
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Multilevel Queue

import java.io.*;
import java.util.*;
class process
{
String name;
int burst;
boolean done;
int wt;
process(String x, int y)
{
name=x;
burst=y;
done=false;
}
public String toString()
{
return(name+"||");
}
}
class rr
{
public static void main(String[] args) throws IOException
{
BufferedReader br= new BufferedReader (new InputStreamReader(System.in));
System.out.println("Enter no. of processes: ");
int n=Integer.parseInt(br.readLine());
process a[]=new process[n];
for (int i=0;i<n ;i++ )
{
System.out.println("Enter name");
String name=br.readLine();
System.out.println("Enter Burst Time");
int time=Integer.parseInt(br.readLine());
a[i]=new process(name,time);
}
System.out.println("Enter time slice :");
int ts=Integer.parseInt(br.readLine());
int donecount=0;
int j=0;
int ctime=0;
int k;
do
{
if (a[j].burst<=ts && a[j].done==false)
{
for (k=0;k<a.length ;k++ )
{
if (a[k].done==false && k!=j)
a[k].wt+=a[j].burst;
}
ctime+=a[j].burst;
a[j].burst=0;
a[j].done=true;
donecount++;
}
else if(a[j].burst>ts && a[j].done==false)
{
for ( k=0;k<a.length ;k++ )
{
if (a[k].done==false && k!=j)
a[k].wt+=ts;
}
if(ctime == 0 && over > 0) //PRIORITY QUEUE
{
if (a[k].done==false && k!=j)
a[k].wt+=a[j].burst;
}
ctime+=a[j].burst;
a[j].burst=0;
a[j].done=true;
donecount++;
}
else if(ctime>5 && over >0) //FIFO QUEUE
{
if (a[k].done==false && k!=j)
a[k].wt+=a[j].burst;
}
ctime+=a[j].burst;
a[j].burst=0;
a[j].done=true;
donecount++;
}
ctime+=ts;
a[j].burst-=ts;
}
if(j==a.length-1)
j=0;
else
j++;
if(donecount==a.length)
break;
}
while (true);
process arr[]=new process[100];
int index=0;
int twt=0;

System.out.println("Waiting time:");
for (int m=0;m<a.length ;m++ )
{
System.out.println("WT of process "+a[m].name+" is :"+a[m].wt);
twt+=a[m].wt;
}
System.out.println("Total Waiting time:"+twt);
System.out.println("Average Waiting Time:"+((float)twt/a.length));

System.out.println("Total turnaround Time:"+(twt+ctime));


System.out.println("Average Turnaround Time:"+((float)(twt+ctime)/a.length));
}
}

OUTPUT:
C:\jdk1.3\bin>javac rr.java

C:\jdk1.3\bin>java rr
Enter no. of processes:
4
Enter name
p1
Enter Burst Time
53
Enter name
p2
Enter Burst Time
17
Enter name
p3
Enter Burst Time
68
Enter name
p4
Enter Burst Time
24
Enter time slice :
20

Waiting time:
WT of process p1 is :60
WT of process p2 is :0
WT of process p3 is :116
WT of process p4 is :12
Total Waiting time:188
Average Waiting Time:47
Total turnaround Time:350
Average Turnaround Time:87.5

You might also like