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

OS Assignment 1

The document provides a C program that simulates the First-Come, First-Served (FCFS) CPU scheduling algorithm. It calculates the waiting time and turnaround time for a set of processes based on their arrival and burst times. The program outputs the waiting time and turnaround time for each process, along with the average waiting and turnaround times.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views3 pages

OS Assignment 1

The document provides a C program that simulates the First-Come, First-Served (FCFS) CPU scheduling algorithm. It calculates the waiting time and turnaround time for a set of processes based on their arrival and burst times. The program outputs the waiting time and turnaround time for each process, along with the average waiting and turnaround times.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Assignment -1

1. Write a C program to simulate the FCFS CPU scheduling


algorithms to find turnaround time and waiting time.
#include<stdio.h>

int main()

int AT[10],BT[10],WT[10],TT[10],n;

int burst=0,cmpl_T;

float Avg_WT,Avg_TT,Total=0;

printf("Enter number of the process\n");

scanf("%d",&n);

printf("Enter Arrival time and Burst time of the process\n");

printf("AT\tBT\n");

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

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

// Logic for calculating Waiting time

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

if(i==0)
WT[i]=AT[i];

else

WT[i]=burst-AT[i];

burst+=BT[i];

Total+=WT[i];

Avg_WT=Total/n;

// Logic for calculating Turn around time

cmpl_T=0;

Total=0;

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

cmpl_T+=BT[i];

TT[i]=cmpl_T-AT[i];

Total+=TT[i];

Avg_TT=Total/n;

// printing of outputs

printf("Process ,Waiting_time ,TurnA_time\n");


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

printf("%d\t\t%d\t\t%d\n",i+1,WT[i],TT[i]);

printf("Average waiting time is : %f\n",Avg_WT);

printf("Average turn around time is : %f\n",Avg_TT);

return 0;

Turn Around Time = Completion Time - Arrival Time


Waiting Time = Turnaround time - Burst Time

You might also like