0% found this document useful (0 votes)
6 views3 pages

Name: Ajay Chauhan Branch:CSIT-4A Roll No: 2400290119001

The document outlines a C program that implements the Shortest Job First (SJF) scheduling algorithm. It prompts the user to input the number of processes, their arrival times, and burst times, then calculates and displays completion times, turnaround times, and waiting times for each process. Finally, it computes and prints the average waiting time and average turnaround time.

Uploaded by

thakurajay8865
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Name: Ajay Chauhan Branch:CSIT-4A Roll No: 2400290119001

The document outlines a C program that implements the Shortest Job First (SJF) scheduling algorithm. It prompts the user to input the number of processes, their arrival times, and burst times, then calculates and displays completion times, turnaround times, and waiting times for each process. Finally, it computes and prints the average waiting time and average turnaround time.

Uploaded by

thakurajay8865
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Name: Ajay Chauhan

Branch:CSIT-4A

Roll no: 2400290119001

Lab:-2

Object: Implement shortest job first algorithm using c programming.

#include <stdio.h>

int main() {

int n, i, j, min, temp;

int at[20], bt[20], ct[20], wt[20], tat[20], pid[20];

int completed[20] = {0};

float avg_wt = 0, avg_tat = 0, time = 0;

printf("Enter the number of processes: ");

scanf("%d", &n);

for(i = 0; i < n; i++) {

printf("Enter Arrival Time for Process P[%d]: ", i + 1);

scanf("%d", &at[i]);

printf("Enter Burst Time for Process P[%d]: ", i + 1);

scanf("%d", &bt[i]);

pid[i] = i + 1;

int count = 0;

while(count < n) {

min = -1;
for(i = 0; i < n; i++) {

if(at[i] <= time && completed[i] == 0) {

if(min == -1 || bt[i] < bt[min]) {

min = i;

if(min == -1) {

time++;

} else {

ct[min] = time + bt[min];

tat[min] = ct[min] - at[min];

wt[min] = tat[min] - bt[min];

avg_wt += wt[min];

avg_tat += tat[min];

completed[min] = 1;

time = ct[min];

count++;

printf("\nProcess\tAT\tBT\tCT\tTAT\tWT\n");

for(i = 0; i < n; i++) {

printf("P[%d]\t%d\t%d\t%d\t%d\t%d\n", pid[i], at[i], bt[i], ct[i], tat[i], wt[i]);


}

printf("\nAverage Waiting Time = %.2f", avg_wt / n);

printf("\nAverage Turnaround Time = %.2f\n", avg_tat / n);

return 0;

Output
Enter the number of processes: 2

Enter Arrival Time for Process P[1]: 1

Enter Burst Time for Process P[1]: 4

Enter Arrival Time for Process P[2]: 0

Enter Burst Time for Process P[2]: 6

Process AT BT CT TAT WT

P[1] 1 4 10 9 5

P[2] 0 6 6 6 0

Average Waiting Time = 2.50

Average Turnaround Time = 7.50

You might also like