Priority queue You have been asked to test the effectiveness of the following di
ID: 3828557 • Letter: P
Question
Priority queue You have been asked to test the effectiveness of the following different scheduling algorithms for different types of queuing applications. 1) First-In-First-out (FIFo): The jobs a processed in the arriving order. The job at the front of the queue is served until it has completed. That job is then removed from the queue. The next job at the front of the queue is served until it has completed and then it is removed from the queue. This process is continued until the queue is empty. 2) Shortest-Job-First (SJF): The job with the shortest processing time is processed first until it has completed. That job is then removed from the queue. The next job with smallest processing is then served until it has completed and then it is removed from the queue. This process is continued until the queue is empty.Explanation / Answer
The FIFO java Code :
import java.io.*;
public class fifo
{
public static void main(String[] args) throws Exception
{
int f,p,num=0, pageHit=0;
int pages[];
int frame[];
boolean flag = true;
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter number of frames : ");
f = Integer.parseInt(br.readLine());
System.out.println("Enter number of pages : ");
p = Integer.parseInt(br.readLine());
frame = new int[f];
pages = new int[p];
for(int i=0; i<f; i++)
{
frame[i] = -1;
}
System.out.println("Enter page number : ");
for(int i=0;i<p;i++)
pages[i] = Integer.parseInt(br.readLine());
for(int i=0; i<p; i++)
{
flag = true;
int page = pages[i];
for(int j=0; j<f; j++)
{
if(frame[j] == page)
{
flag = false;
pageHit++;
break;
}
}
if(num == f)
num = 0;
if(flag)
{
frame[num] = page;
num++;
}
System.out.print("frame : ");
for(int k=0; k<f; k++)
System.out.print(frame[k]+" ");
System.out.println();
}
System.out.println("No. of page hit : "+pageHit);
}
}
OUTPUT:
C:mp>javac fifo.java
C:mp>java fifo
Enter number of frames :
3
Enter number of pages :
6
Enter page number :
3
2
2
4
5
4
frame : 3 -1 -1
frame : 3 2 -1
frame : 3 2 -1
frame : 3 2 4
frame : 5 2 4
frame : 5 2 4
No. of page hit : 2
Java Program for SJF:
OUTPUT:
Enter no of process
4
Enter Burst time for each process
Enter BT for process 1
5
Enter BT for process 2
3
Enter BT for process 3
3
Enter BT for process 4
1
PROCESS BT WT TAT
0 1 0 1
1 3 1 4
2 3 4 7
3 5 7 12
***********************************************
Avg waiting time=3.0
***********************************************
*/
Java Program for Round Robin:
OUTPUT:
Enter number of process:
4
Enter brust Time:
Enter brust Time for 1
4
Enter brust Time for 2
5
Enter brust Time for 3
6
Enter brust Time for 4
7
Enter Time quantum:
4
process BT WT TAT
process1 4 0 4
process2 5 12 17
process3 6 13 19
process4 7 15 22
average waiting time 10.0
Average turn around time15.5
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.