0% found this document useful (0 votes)
58 views6 pages

Lab No. 7: Lab Manual For Operating System

The document discusses the First Come First Serve (FCFS) scheduling algorithm, which executes processes in the order of their arrival. It provides two examples of code implementing FCFS scheduling, with the second accounting for processes arriving at different times. The document concludes with tasks for students to modify and extend the FCFS code examples.

Uploaded by

Dania Ahmad
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)
58 views6 pages

Lab No. 7: Lab Manual For Operating System

The document discusses the First Come First Serve (FCFS) scheduling algorithm, which executes processes in the order of their arrival. It provides two examples of code implementing FCFS scheduling, with the second accounting for processes arriving at different times. The document concludes with tasks for students to modify and extend the FCFS code examples.

Uploaded by

Dania Ahmad
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/ 6

Lab Manual for Operating System

Lab No. 7
First Come First Serve Scheduling Algorithm

Objectives
To understand basic concept, working and usage of scheduling algorithm.
LAB # 07
The FCFS Scheduling Algorithm

Short-Term Scheduling
Short-term scheduling, or dispatching, involves scheduling processes to execute on a processor.
Whenever the CPU becomes idle, the operating system must select one of the processes in the ready
queue to be executed. The selection process is carried out by the short-term scheduler. It selects a
process from the processes in memory that are ready to execute and allocates the CPU to that process.

There are various algorithms available for scheduling processes. Some of these are discussed in this
manual while the rest are left for the students as tasks.

First Come First Serve (FCFS)


FCFS is a relatively simple algorithm, which treats the processes strictly in order of arrival. Processor is
allocated to the process which arrives first. Once the processor is allocated to a process, it is released
when that process finishes. When the processor is available, the scheduler selects the next process to be
executed.

The codes provided in Example#01 and Example#02 are implementations of the FCFS algorithms. In the
code provided in Example#01, it is assumed that all processes are present in the system at the same
time; that is, all processes have arrived in the system. However, the processes usually arrive at different
times. In order to accommodate processes arriving at different times, the code in Example#01 can be
modified as given in Example#02.

 Completion Time: Time at which process completes its execution.


 Turn Around Time: Time Difference between completion time and arrival time. Turn Around
Time = Completion Time – Arrival Time
 Waiting Time(W.T): Time Difference between turn around time and burst time.
Waiting Time = Turn Around Time – Burst Time
 Burst time can be calculated as the difference of the Completion Time of the process and the
Waiting Time
Example#01:

#include<stdio.h>
void main (void)
{
int st[20], wt[20], tat[20], i, n;
float wt_avg, tat_avg;

printf("\nEnter the number of processes: ");


scanf("%d", &n);

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


{
printf("\nEnter Burst/Service time for process%d: ", i);
scanf("%d", &st[i]);
}
wt[0] = wt_avg = 0;
tat[0] = tat_avg = st[0];

for (i = 1; i < n; i++)


{
wt[i] = wt[i-1] + st[i-1];
tat[i] = tat[i-1] + st[i];

wt_avg = wt_avg + wt[i];


tat_avg = tat_avg + tat[i];
}
printf("\n PROCESS \t SERVICE TIME \t WAITING TIME \t TURNAROUND TIME\n");

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


{
printf("\nP%d \t\t%d \t\t%d \t\t%d\n", i, st[i], wt[i], tat[i]);
}
printf("\nAverage waiting time:%f ", wt_avg/n);
printf("\nAverage turnaround time:%f \n", tat_avg/n);
}
Example#02:

#include<stdio.h>
void main (void)
{
int at[20], st[20], wt[20], ft[20], tat[20], i, n;
float wt_avg, tat_avg;

printf("\nEnter the number of processes: ");


scanf("%d", &n);

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


{
printf("\nEnter the Arrival time for process%d: ", i);
scanf("%d", &at[i]);
printf("\nEnter Burst/Service time for process%d: ", i);
scanf("%d", &st[i]);
}
wt[0] = wt_avg = 0;
tat[0] = tat_avg = st[0];
ft[0] = st[0];

for (i = 1; i < n; i++)


{
if (at[i] <= at[i+1])
{
wt[i] = wt[i-1] + st[i-1];
ft[i] = wt[i] + st[i];
tat[i] = ft[i] - at[i];

wt_avg = wt_avg + wt[i];


tat_avg = tat_avg + tat[i];
}
}
printf("\n PROCESS \t SERVICE TIME \t WAITING TIME \t FINISH TIME \t TURNAROUND TIME\n");

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


{
printf("\nP%d \t\t%d \t\t%d \t\t%d \t\t%d\n", i, st[i], wt[i], ft[i], tat[i]);
}

printf("\nAverage waiting time:%f ", wt_avg/n);


printf("\nAverage turnaround time:%f \n", tat_avg/n);

}
Lab Tasks/Practical Work
1) Implement the codes of Example#01 and Example#01. Discuss what you have learned after
implementing and executing these two codes. Provide snapshots of the generated outputs.

2) The FCFS source code given above assumes that the arrival times for processes are provided in
ascending order of time. Modify the code in C language for random process arrival times.

3) Modify the FCFS code of example#02 to be able to calculate the mean of Normalized Turnaround
Time. Also the modified code should display the Normalized Turnaround Time of each process.

You might also like