TO IMPLEMENT First Come First Service
*/
import java.util.*;
public class FCFS
{
public static void main(String args[])throws Exception{
Scanner s=new Scanner(System.in);
int n=0;
System.out.print("Enter no of processes :");
n=s.nextInt();
Process[] p=new Process[n];
for(int i=0;i<n;i++)
{
p[i]=new Process();
}
for(int i=0;i<n;i++)
{
System.out.print("PROCESS ID :");
p[i].id=s.nextInt();
System.out.println("ARRIVAL TIME :"+i);
p[i].atime=i;
System.out.print("Burst TIME :");
p[i].btime=s.nextInt();
}
/*for(int i=0;i<n-1;i++)
{
for(int j=0;j<n-1;j++)
{
if(p[j].atime>p[j+1].atime)
{
Process t=p[j];
p[j]=p[j+1];
p[j+1]=t;
}
}
}
System.out.println("Process id\tArrival time\tBurst time");
System.out.println("...............................");
for(int i=0;i<n;i++)
{
System.out.println(""+p[i].id+"\t\t"+p[i].atime+"\t\t"+p[i].btime);
}
*/
System.out.print("\nStarting to execute process");
for(int i=0;i<n;i++)
{
System.out.print("\nProcess "+p[i].id+" under execution");
Thread.sleep((p[i].btime)*1000);
System.out.println("\nProcess "+p[i].id+" executed");
}
}
}
class Process {
int id,btime,atime;
}
/*OUTPUT
bash-3.00$ java FCFS
bash-3.00$ java FCFS
Enter no of processes :3
PROCESS ID :1
ARRIVAL TIME :0
Burst TIME :7
PROCESS ID :2
ARRIVAL TIME :1
Burst TIME :1
PROCESS ID :3
ARRIVAL TIME :2
Burst TIME :3
Starting to execute process
Process 1 under execution
Process 1 executed
Process 2 under execution
Process 2 executed
Process 3 under execution
Process 3 executed
*/
No comments:
Post a Comment