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

OS lab 1

The document outlines a lab assignment focused on simulating process scheduling using First-Come, First-Served (FCFS) and Shortest Job First (SJF) algorithms. It includes problem descriptions, formulae for calculating Completion Time, Turnaround Time, and Waiting Time, as well as detailed algorithms for both scheduling methods. The assignment requires the implementation of a program that calculates and displays the scheduling criteria for each algorithm based on given processes.

Uploaded by

shivanggarg993
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)
5 views

OS lab 1

The document outlines a lab assignment focused on simulating process scheduling using First-Come, First-Served (FCFS) and Shortest Job First (SJF) algorithms. It includes problem descriptions, formulae for calculating Completion Time, Turnaround Time, and Waiting Time, as well as detailed algorithms for both scheduling methods. The assignment requires the implementation of a program that calculates and displays the scheduling criteria for each algorithm based on given processes.

Uploaded by

shivanggarg993
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
You are on page 1/ 4

Lab Assignment 1: Process Scheduling (FCFS & SJF)

Problem Description

Write a program that simulates process scheduling based on First-Come, First-


Served (FCFS) and Shortest Job First (SJF) scheduling algorithms. Given a set of
processes with their Process ID (PID), Arrival Time, and Burst Time, calculate
the Completion Time (CT), Waiting Time (WT) and Turnaround Time (TAT).
The program should calculate and display the scheduling criteria for each
algorithm.

Formulae :-
1. Completion Time (CT) = Current Time + Burst Time
2. Turnaround Time(TAT) = Completion Time – Arrival Time
3. Waiting Time (WT) = Turnaround Time – Burst Time

Solution :-

Algorithm for First-Come, First-Served (FCFS) Scheduling


1. Sort processes by Arrival Time (AT).
2. Initialize currentTime = 0, totalWT = 0, totalTAT = 0.
3. For each process:
o If currentTime < AT, update currentTime = AT.
o Compute Completion Time (CT) = currentTime + Burst Time (BT).
o Compute Turnaround Time (TAT) = CT - AT.
o Compute Waiting Time (WT) = TAT - BT.
o Update currentTime = CT, add WT and TAT to totals.
4. Print process details and average WT & TAT.

Algorithm for Shortest Job First (SJF) Scheduling


1. Sort processes by Arrival Time (AT).
2. Initialize currentTime = 0, completed = 0, totalWT = 0, totalTAT = 0.
3. While all processes are not completed:
o Add processes with AT ≤ currentTime to Ready Queue.
o Sort Ready Queue by Burst Time (BT).
o Select the process with the shortest BT, remove from queue.
o Compute CT, TAT, WT as in FCFS.
o Update currentTime = CT, increment completed.
o If no process is ready, increment currentTime.
4. Print process details and average WT & TAT.

CODE :-
OUTPUT :-

You might also like