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

Fcfs With Arrival

operataing system practial file of fcfs eith arrival time
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)
10 views3 pages

Fcfs With Arrival

operataing system practial file of fcfs eith arrival time
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

Experiment No.

4b

Objective :
Implement CPU Scheduling Policies of FCFS algorithm with arrival time.

Theory :

FCFS is a non-preemptive CPU scheduling algorithm that functions on a simple principle:


processes are allocated the CPU on a "first-in, first-served" basis. It's like a waiting line
where the first person in line gets served first.

Program :

#include <stdio.h>

int main() {

int n, i, current_time = 0, waiting_time = 0, turnaround_time = 0;

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

scanf("%d", &n);

int pid[n], arrival_time[n], burst_time[n], completion_time[n];

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

printf("Enter process ID: ");

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

printf("Enter arrival time: ");

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

printf("Enter burst time: ");

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

}
// Sort processes by arrival time

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

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

if (arrival_time[j] > arrival_time[j + 1]) {

// Swap process data

int temp_pid = pid[j];

pid[j] = pid[j + 1];

pid[j + 1] = temp_pid;

int temp_arrival_time = arrival_time[j];

arrival_time[j] = arrival_time[j + 1];

arrival_time[j + 1] = temp_arrival_time;

int temp_burst_time = burst_time[j];

burst_time[j] = burst_time[j + 1];

burst_time[j + 1] = temp_burst_time;

printf("Process ID\tArrival Time\tBurst Time\tCompletion Time\tWaiting Time\


tTurnaround Time\n");

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

if (current_time < arrival_time[i]) {

current_time = arrival_time[i];

completion_time[i] = current_time + burst_time[i];


current_time = completion_time[i];

waiting_time += completion_time[i] - arrival_time[i] - burst_time[i];

turnaround_time += completion_time[i] - arrival_time[i];

printf("%d\t\t%d\t\t%d\t\t%d\t\t%d\t\t%d\n", pid[i], arrival_time[i], burst_time[i],


completion_time[i], waiting_time, turnaround_time);

printf("\nAverage Waiting Time: %.2f\n", (float)waiting_time / n);

printf("Average Turnaround Time: %.2f\n", (float)turnaround_time / n);

return 0;

Output :

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy