PROGRAM TO IMPLEMENT CPU SCHEDULING POLICIES in JAVA


import java.io.*;
import java.util.*;
class schpol
{ public static void main(String []arg)throws IOException
{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
int i,j,t=0,tun=0,ch,q;
String s;
int []ind=new int[10];
int []arr=new int[10];
int []burst=new int[10];
int []bur=new int[10];
System.out.println("enter no of processes :");
int n=Integer.parseInt(b.readLine());
for(i=0;i0)
{ t= (tun)-arr[i] ;
if(t>0)
{ System.out.println(" process p"+i+" waiting for "+t ); }
else
{ System.out.println("idle for "+Math.abs(t) +" time"); }

tun=tun+burst[i];
}
else
{ tun=burst[i]; }

for(j=0;j for(j=0;j { System.out.println("----");
}
System.out.println(" process p"+ind[i]+" completed");
}
break;

case 3:
tun=0;
System.out.println("enter quatum no:");
q=Integer.parseInt(b.readLine());
i=0;
tun=burst[i];
while(tun!=0)
{
for(i=0;i {
for(j=0;j { if(burst[i]!=0)
{
System.out.println("process p"+i+" executing .......");
burst[i]=burst[i]-1;
t++;
if(burst[i]==0)
{
System.out.println("process p"+i+" completed ");
break;
}
}
}
if(t { System.out.println("processor idle "); }
}
tun=0;
for(i=0;i { tun=tun+burst[i]; }
}
break;
}
System.out.println("do u want to continue(y/n) ");
s=b.readLine();
}
while(s.equals("y"));

}
}

0 comments :