Professional Documents
Culture Documents
Experiment No.9: Simulation
Experiment No.9: Simulation
9
Simulation of SJF Scheduling Algorithm
2. Code:
#include <stdio.h>
using namespace std;
int main()
{
int a[] = { 0, 1, 2},
b[] = {1, 2, 3},
bt[] = {5, 6, 2};
printf("Process\tAT\tBT\t\n");
for(int i=0; i<3; i++)
printf("P%d\t%d\t%d\n", a[i], b[i], bt[i]);
for(int i=0;i<3; i++)
{
for(int j=i+1; j<3; j++)
{
if(bt[i] > bt[j])
{
int temp = bt[i];
bt[i] = bt[j];
bt[j] = temp;
temp = b[i];
b[i] = b[j];
b[j] = temp;
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
printf("\n\nProcess\tAT\tBT\t\n");
for(int i=0; i<3; i++)
printf("P%d\t%d\t%d\n", a[i], b[i], bt[i]);
return 0;
}
Output:
Learning outcomes:
3. I learned about the Turnaround, Finish time and how to find average
Turnaround and Finish time.
4. I learned about the Waiting time and how to find average Waiting time.
5. I learned about the CPU scheduling with the help of this experiment.