Scheduling Algorithms
Scheduling Algorithms
#include<stdio.h>
#include<conio.h>
void main()
scanf("%d", &NOP);
// Use for loop to enter the details of the process like Arrival time and the Burst Time
printf("\n Enter the Arrival and Burst time of the Process[%d]\n", i+1);
scanf("%d", &at[i]);
scanf("%d", &bt[i]);
scanf("%d", &quant);
// Display the process No, burst time, Turn Around Time and the waiting time
printf("\n Process No \t\t Burst Time \t\t TAT \t\t Waiting Time ");
for(sum=0, i = 0; y!=0; )
{
temp[i] = 0;
count=1;
printf("\nProcess No[%d] \t\t %d\t\t\t\t %d\t\t\t %d", i+1, bt[i], sum-at[i], sum-at[i]-bt[i]);
wt = wt+sum-at[i]-bt[i];
tat = tat+sum-at[i];
count =0;
if(i==NOP-1)
i=0;
else if(at[i+1]<=sum)
i++;
else
i=0;
}
avg_wt = wt * 1.0/NOP;
getch();
Process No[1] 4 1 -3
Process No[2] 3 3 0
FCFS:
#include<stdio.h>
int main()
int n,bt[30],wait_t[30],turn_ar_t[30],av_wt_t=0,avturn_ar_t=0,i,j;
printf("Please enter the total number of processes(maximum 30):"); // the maximum process that
be used to calculate is specified.
scanf("%d",&n);
printf("P[%d]:",i+1);
scanf("%d",&bt[i]);
wait_t[0]=0;
for(i=1;i<n;i++)
wait_t[i]=0;
for(j=0;j<i;j++)
wait_t[i]+=bt[j];
for(i=0;i<n;i++)
turn_ar_t[i]=bt[i]+wait_t[i];
av_wt_t+=wait_t[i];
avturn_ar_t+=turn_ar_t[i];
printf("\nP[%d]\t\t%d\t\t\t%d\t\t\t\t%d",i+1,bt[i],wait_t[i],turn_ar_t[i]);
av_wt_t/=i;
avturn_ar_t/=i; // average calculation is done here
return 0;
P[2]:3
P[1] 2 0 2
P[2] 3 2 5
#include <stdio.h>
int main()
int A[100][4];
scanf("%d", &n);
scanf("%d", &A[i][1]);
A[i][0] = i + 1;
index = i;
index = j;
temp = A[i][1];
A[i][1] = A[index][1];
A[index][1] = temp;
temp = A[i][0];
A[i][0] = A[index][0];
A[index][0] = temp;
A[0][2] = 0;
A[i][2] = 0;
A[i][2] += A[j][1];
total += A[i][2];
avg_wt = (float)total / n;
total = 0;
printf("P BT WT TAT\n");
// data.
for (i = 0; i < n; i++) {
total += A[i][3];
avg_tat = (float)total / n;
P1: 3
P2: 1
P BT WT TAT
P2 1 0 1
P1 3 1 4
Priority scheduling:
#include<stdio.h>
struct priority_scheduling {
char process_name;
int burst_time;
// waiting time of a process
int waiting_time;
int turn_around_time;
int priority;
};
int main() {
int number_of_process;
int total = 0;
// swapping position
int position;
float average_waiting_time;
// average turnaround time of the process
float average_turnaround_time;
ASCII_number++;
position = i;
position = j;
temp_process = process[i];
process[i] = process[position];
process[position] = temp_process;
// First process will not have to wait and hence has a waiting time of 0
process[0].waiting_time = 0;
process[i].waiting_time = 0;
process[i].waiting_time += process[j].burst_time;
total += process[i].waiting_time;
total = 0;
printf("------------------------------------------------------------\n");
total += process[i].turn_around_time;
printf("\n-----------------------------------------------------------\n");
return 0;
}
------------------------------------------------------------
B 5 0 5
-----------------------------------------------------------
A 3 5 8
-----------------------------------------------------------