First Come First Serve (FCFS) Source Code:: C. Algorithm Simulation
First Come First Serve (FCFS) Source Code:: C. Algorithm Simulation
Algorithm Simulation
int temp;
for (int j = 0; j < n; j++) {
for (int k = j+1; k < n; k++) {
if (at[j] > at[k]) {
temp = pd[j];
pd[j] = pd[k];
pd[k] = temp;
temp = at[j];
at[j] = at[k];
at[k] = temp;
temp = bt[j];
bt[j] = bt[k];
bt[k] = temp;
}
}
}
System.out.println("Gantt Chart");
System.out.println();
System.out.println("Turn-Around Time : " + (tatave));
System.out.println("Average Turn-Around Time : " +
(tatave/n) + "ms");
System.out.println("Waiting Time : " + (wtave));
System.out.println("Average Waiting Time : " + (wtave/n) +
"ms");
}
}
FCFS Flowchart
Start
int pd [ ] = 0
int at [ ] = 0
int bt [ ] = 0
int ct [ ] = 0
int ta [ ] = 0
int wt [ ] = 0
int f [ ] = 0
int st [ ] = 0
int tot [ ] = 0
float avg wt = 0
float avg ta = 0
Input n
i=0
i<n
bt = [ i ]
Display pid at bt ct ta wt
i=0 i = i + tt
Display
avg wt /n
avg ta /n
Display
avg wt
avg ta
STOP
Shortest Job First (SJF)
Source Code :
package osfinals;
import java.util.Scanner;
public class Sjf {
}
SJF Flowchart
Start
int pid [ ] = 0
int ar [ ] = 0
int bt [ ] = 0
int ct [ ] = 0
int ta [ ] = 0
int wt [ ] = 0
float avg wt = 0
float avg ta = 0
Input n
i=0
i=i+1
i<n
ar =1 ;
bt = 1;
A
temp = ar [ j ];
ar [ j ] = ar [ j + 1 ];
ar[ j + 1] = temp;
temp = b[ j + 1 ];
bt [ j ] = bt [ j + 1 ];
bt [ j + 1 ] = temp;
temp = pid [ j ];
pid [ j ] = pid [ j + 1 ];
pid [ j + 1 ] = temp;
i=0 i = i++
c t [ i ] = ar [ i ] + bt [ i ];
ar [ i ] > ct [ i – 1] c t [ i ] =ct [ i - 1] + bt [ i ];
c t [ i ] = ar [ i ] + bt [ i ]
ta [ i ] = ct [ i ] – ar [ i ];
wt [ i ] = at [ i ] – bt [ i ];
avgwt + = wt [ i ];
avgta + = ta [ i ];
pid [ i ] = i + 1;
f [ i ] = 0;
ct [ a ] = st + bt [ a ];
a=n min = 999
st = bt [ a ];
ta [ a ] = ct [ a ] – at [ a ];
wt [ a ] = ta [ a ] – bt [ a ];
f[a]=1
atA[ i ] < =st &&
f [i] ==0 && bt [ i ] < min
pid at BT CT WT
avg wt + = wt [ i ]
i++
avg ta + = ta [ i ]
pid [ i ] + at [ i ] + bt [ i ] + ct [ i ] + ta [ i ] + wt [ i ]
avg ta\n
avg wt \n
if (b == no_Process) {
count++;
continue;
}
if (process.get(iiiii).burstTime <= 0) {
process.get(iiiii).completion = count;
System.out.println(" this one
"+process.get(iiiii).processName+""+process.get(iiiii).completion);
}
}
}
}
}
static class process {
String processName;
int arrivalTime;
int burstTime;
int burstTime1;
int completion;
int waitingTime;
int startTime;
double ratio;
double num;
int turnaroundtime;
int priorityvalue;
Scanner input = new Scanner(System.in);
process() {
System.out.print("Enter the name of the
process = ");
processName = input.next();
System.out.print("Enter the Arrival time of
the process = ");
arrivalTime = input.nextInt();
System.out.print("Enter the Burst time of
the process = ");
burstTime = input.nextInt();
System.out.print("Enter the pririty value of
the process = ");
priorityvalue = input.nextInt();
System.out.println();
}
}
}
Non-Preemptive
Source Code
package osfinals;
import java.util.Scanner;
int x,n,p[],pp[],bt[],w[],t[],i;
float awt = 0;
float atat = 0;
p = new int[10];
pp = new int[10];
bt = new int[10];
w = new int[10];
t = new int[10];
for(i=0;i<n;i++){
System.out.print("\nProcess["+(i+1)+"]:");
bt[i] = s.nextInt();
pp[i] = s.nextInt();
p[i]=i+1;
}
}
}
}
NPP Flowchart
Start
int pid [ ]
int at [ ]
int bt [ ]
int ct [ ]
int ta [ ]
int wt [ ]
int f [ ]
int st = 0
int tot = 0
float avg wt = 0
float avg ta = 0
i=0
i<=n i=i+2
pid a [ i ] = i + 1
f[i]=0
A
c = n min = 999
i=0
tot = = 0
i ++ i<n
at [ i ] < = st &&
f [ i ] == 0 &&
bt [ i ] < min
min = bt [ i ]
c=1
c==n
c++
ct [ c ] = st + bt [ c ];
st [ ] = bt [ c ]
ta [ c ] = ct [ c ] – at [ c ];
wt [ c ] = ta [ c ] – bt [ c ];
f[c]=1
tot ++
i<n i=0
avg wt = wt [ i ]
avg tat = ta [ i ]
Print pi [ i ] + at[ i ] + bt [ i ] + ct [ i ] + ta [ i ] + wt [ i ]
Stop
Round Robin
Source Code
package osfinals;
public static void roundRobin(String p[], int a[],
int res = 0;
int resc = 0;
res_b[i] = b[i];
res_a[i] = a[i];
int t = 0;
while (true) {
if (res_a[i] <= t) {
if (res_a[i] <= n) {
if (res_b[i] > 0) {
flag = false;
if (res_b[i] > n) {
t = t + n;
res_b[i] = res_b[i] - n;
res_a[i] = res_a[i] + n;
else {
t = t + res_b[i];
comp[i] = t - a[i];
res_b[i] = 0;
// add sequence
// compare
if (res_b[j] > 0) {
flag = false;
t = t + n;
res_b[j] = res_b[j] - n;
res_a[j] = res_a[j] + n;
else {
t = t + res_b[j];
comp[j] = t - a[j];
res_b[j] = 0;
}
}
// ith is process
if (res_b[i] > 0) {
flag = false;
if (res_b[i] > n) {
t = t + n;
res_b[i] = res_b[i] - n;
res_a[i] = res_a[i] + n;
else {
t = t + res_b[i];
comp[i] = t - a[i];
res_b[i] = 0;
t++;
i--;
}
if (flag) {
break;
+ (float)res / p.length);
+ (float)resc / p.length);
// Driver Code
int q = 3;