0% found this document useful (0 votes)
84 views5 pages

C Program

The document describes the First Come First Serve (FCFS) scheduling algorithm. It explains that FCFS schedules processes in the order they arrive, without preemption. The key steps are: (1) input process burst times, (2) calculate waiting times by adding previous process burst times, (3) calculate turnaround times by adding waiting and burst times, (4) calculate average waiting and turnaround times. FCFS has the advantages of simplicity but the disadvantage of potential long waits for shorter jobs due to lack of preemption. Pseudocode is provided to implement FCFS scheduling.

Uploaded by

Rohit
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)
84 views5 pages

C Program

The document describes the First Come First Serve (FCFS) scheduling algorithm. It explains that FCFS schedules processes in the order they arrive, without preemption. The key steps are: (1) input process burst times, (2) calculate waiting times by adding previous process burst times, (3) calculate turnaround times by adding waiting and burst times, (4) calculate average waiting and turnaround times. FCFS has the advantages of simplicity but the disadvantage of potential long waits for shorter jobs due to lack of preemption. Pseudocode is provided to implement FCFS scheduling.

Uploaded by

Rohit
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/ 5

C program to implement the FCFS(FIRST COME FIRST SERVE) scheduling algorithm

AIM

To write a program to implement the FCFS scheduling algorithm

ALGORITHM

1. Start the process

2. Declare the array size

3. Get the number of processes to be inserted

4. Get the value

5. Start with the first process from it’s initial position let other process to be in queue

6. Calculate the total number of burst time


7.  Display the values

8. Stop the process

First Come First Serve (FCFS):

In this algorithm, the CPU is allocated to the processes in the order they request it.
The implementation of FCFS is easily done with a queue (a FIFO structure). When the first process enters
the system it starts its execution immediately and runs till it completes its execution.

Advantage:

It is easy to understand and implement.

Disadvantage:

It is a Non-Pre-emptive scheduling algorithm: Once a process has been allocated the CPU, it will not
release the CPU until it finishes executing. Thus, it is not suitable for modern systems which work on the
principle of time sharing.

The Average Waiting Time is high.


It results in CONVOY EFFECT i.e., many processes which require CPU for short duration have to wait for a
bigger process to finish thus resulting in low resource utilization.

Implementation:

1- Input the processes along with their burst time (bt).

2- Find waiting time (wt) for all processes.

3- As first process that comes need not to wait so waiting time for process 1 will be 0 i.e. wt[0] = 0.

4- Find waiting time for all other processes i.e. for process i -> wt[i] = bt[i-1] + wt[i-1] .

5- Find turnaround time = waiting_time + burst_time for all processes.

6- Find average waiting time = total_waiting_time / no_of_processes.

7- Similarly, find average turnaround time = total_turn_around_time / no_of_processes.

In the above code, the demonstration of the first come first serve scheduling algorithm is shown. The
user is asked to enter the number of processes. On entering the number of processes, we have to enter
the burst times for each of the processes.

The waiting time is calculated first. First, the waiting time of the first process is zero.
for(i=1;i<n;i++)

  {

      wt[i]=0;

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

          wt[i]+=bt[j];

  }

Calculation of the waiting time is done by adding the burst time of the previous process. Consider the
previous process had a burst time of 10, then the waiting time of second will be 10. Similarly, for the
third process, the waiting time will the sum of burst times of first and second processes.

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

    {

        tat[i]=bt[i]+wt[i];

        avwt+=wt[i];

        avtat+=tat[i];
        printf("nP[%d]tt%dtt%dtt%d",i+1,bt[i],wt[i],tat[i]);

    }

The next part we calculate the turn around time. The turn around time for each process is calculated by
adding the burst time and the waiting time.

Last, the average turn around time and the average waiting time is calculated.

avwt/=i;

avtat/=i;

i gives the total number of processes. We divide the sum of all the waiting times and turn around times
to get the average. This is how the first come first serve algorithm works.

With this, we come to an end of this First Come First Serve Scheduling in C Programming.

You might also like