0% found this document useful (0 votes)
11 views

Lab Report

The document describes implementing the first-come, first-served (FCFS) CPU scheduling algorithm in Python. It includes the objectives, theoretical analysis, sample calculations, program code, results, and conclusion.

Uploaded by

arifrefat86
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Lab Report

The document describes implementing the first-come, first-served (FCFS) CPU scheduling algorithm in Python. It includes the objectives, theoretical analysis, sample calculations, program code, results, and conclusion.

Uploaded by

arifrefat86
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Lab Report

Course Code: CSE325


Course Title: Operating System

Submitted to: Submitted By:


Md. Mafiul Hasan Matin
Mariya Mehajabin
Lecturer, Dept. of
ID: 2022-1-60-363
Computer Science and
Section: 05
Engineering
Experiment Date: 04-02-2024
Lab Experiment: 01

Name of the Experiment: First-Come-First-Serve FCFS) CPU scheduling algorithm


using python.

Objectives: The objective of this experiment is to analyze the FCFS CPU


scheduling algorithm.
 To implement FCFS scheduling algorithm using a FIFO queue which is non-
preemptive.
 understanding the order in which the processes in the queue are
completed.
 Identifies waiting and response times in detail, creating a wait
Response times for the FCF's procedures.

Theoretical Analysis: FCFS is a non-preemptive CPU scheduling algorithm, where


once a process starts executing, it continues until it completes its CPU burst.
Processes are executed in order they arrived in ready queue without considering
their arrival time or priority. The process which arrives first in the ready queue is
firstly assigned the CPU.

Process Arrival Burst Waiting Turn Completion


time time time Around time
time
P1 0 18 0 18 18
P2 1 3 17 20 21
P3 2 3 19 22 24
Total=36
Total=60 Total=63

I)Gantt chart:
P1 P2 P3
0 18 21 24
II)
Total waiting time = 36
Average waiting time = 36/3 = 12
III)
Total turn around time = 60
Average turn around time=60/3 =20
IV.
Total completion time=63
Average completion time =63/3 = 21

Program Code:
def fcfs_scheduling():
print("FIRST COME FIRST SERVE SCHEDULING")
n = int(input("Enter number of processes: "))
processes = []
for i in range(1, n + 1):
arrival_time = int(input(f"Enter arrival time of process P{i}: "))
burst_time = int(input(f"Enter burst time of process P{i}: "))
processes.append((f"P{i}", arrival_time, burst_time))
processes.sort(key=lambda x: x[1]) # Sort processes based on arrival time
exit_time = [0] * n
turnaround_time = [0] * n
waiting_time = [0] * n
gantt_chart = []
for i in range(n):
if i == 0:
exit_time[i] = processes[i][2]
else:
exit_time[i] = exit_time[i - 1] + processes[i][2]

turnaround_time[i] = exit_time[i] - processes[i][1]


waiting_time[i] = turnaround_time[i] - processes[i][2]

gantt_chart.append((processes[i][0], exit_time[i]))

avg_waiting_time = sum(waiting_time) / n
avg_turnaround_time = sum(turnaround_time) / n
avg_completion_time = sum(exit_time) / n
print("\nGantt Chart:")
print("-" * 40)
for entry in gantt_chart:
print(f"| {entry[0]} ", end="")
print("|")
print("-" * 40)
for entry in gantt_chart:
print(f"| {entry[1]:<2} ", end="")
print(f"|\n{'-' * 40}")

print("\nProcess | Arrival | Burst | Exit | Turn Around | Wait |")


for i in range(n):
print("\nAverage Waiting Time: ", avg_waiting_time)
print("Average Turnaround Time: ", avg_turnaround_time)
print("Average Completion Time: ", avg_completion_time)

Result:
Conclusion: FCFS provides an efficient, simple and error-free process scheduling
algorithm that saves valuable CPU resources. The algorithm may be affected by
the convoy effect, where short processes are delayed behind long ones, leading to
inefficient use of the CPU. Also FCFS may not be appropriate for a realistic
scenario with diverse process characteristics, as it can lead to inefficient use of
CPUs and prolonged turnaround time.

You might also like