Javatpoint Logo
Javatpoint Logo

First Come First Serve CPU Process Scheduling in Operating Systems

In this tutorial, we are going to learn an important concept in CPU Process Scheduling Algorithms. The important concept name is First Come First Serve. This is the basic algorithm which every student must learn to understand all the basics of CPU Process Scheduling Algorithms.

First Come First Serve paves the way for understanding of other algorithms. This algorithm may have many disadvantages. But these disadvantages created very new and efficient algorithms. So, it is our responsibility to learn about First Come First Serve CPU Process Scheduling Algorithms.

Important Abbreviations

  1. CPU - - - > Central Processing Unit
  2. FCFS - - - > First Come First Serve
  3. AT - - - > Arrival Time
  4. BT - - - > Burst Time
  5. WT - - - > Waiting Time
  6. TAT - - - > Turn Around Time
  7. CT - - - > Completion Time
  8. FIFO - - - > First In First Out

First Come First Serve

First Come First Serve CPU Scheduling Algorithm shortly known as FCFS is the first algorithm of CPU Process Scheduling Algorithm. In First Come First Serve Algorithm what we do is to allow the process to execute in linear manner.

This means that whichever process enters process enters the ready queue first is executed first. This shows that First Come First Serve Algorithm follows First In First Out (FIFO) principle.

The First Come First Serve Algorithm can be executed in Pre Emptive and Non Pre Emptive manner. Before, going into examples, let us understand what is Pre Emptive and Non Pre Emptive Approach in CPU Process Scheduling.

Pre Emptive Approach

In this instance of Pre Emptive Process Scheduling, the OS allots the resources to a Process for a predetermined period of time. The process transitions from running state to ready state or from waiting state to ready state during resource allocation. This switching happens because the CPU may assign other processes precedence and substitute the currently active process for the higher priority process.

Non Pre Emptive Approach

In this case of Non Pre Emptive Process Scheduling, the resource cannot be withdrawn from a process before the process has finished running. When a running process finishes and transitions to the waiting state, resources are switched.

Convoy Effect In First Come First Serve (FCFS )

Convoy Effect is a phenomenon which occurs in the Scheduling Algorithm named First Come First Serve (FCFS). The First Come First Serve Scheduling Algorithm occurs in a way of non preemptive way.

The Non preemptive way means that if a process or job is started execution, then the operating system must complete its process or job. Until, the process or job is zero the new or next process or job does not start its execution. The definition of Non Preemptive Scheduling in terms of Operating System means that the Central Processing Unit (CPU) will be completely dedicated till the end of the process or job started first and the new process or job is executed only after finishing of the older process or job.

There may be a few cases, which might cause the Central Processing Unit (CPU) to allot a too much time. This is because in the First Come First Serve Scheduling Algorithm Non Preemptive Approach, the Processes or the jobs are chosen in serial order. Due, to this shorter jobs or processes behind the larger processes or jobs takes too much time to complete its execution. Due, to this the Waiting Time, Turn Around Time, Completion Time is very high.

FCFS Scheduling Algorithms in OS (Operating System)

So, here as the first process is large or completion time is too high, then this Convoy effect in the First Come First Serve Algorithm is occurred.

Let us assume that Longer Job takes infinite time to complete. Then, the remaining processes have to wait for the same infinite time. Due to this Convoy Effect created by the Longer Job the Starvation of the waiting processes increases very rapidly. This is the biggest disadvantage of FCFS CPU Process Scheduling.

Characteristics of FCFS CPU Process Scheduling

The characteristics of FCFS CPU Process Scheduling are:

  1. Implementation is simple.
  2. Does not cause any causalities while using
  3. It adopts a non pre emptive and pre emptive strategy.
  4. It runs each procedure in the order that they are received.
  5. Arrival time is used as a selection criterion for procedures.

Advantages of FCFS CPU Process Scheduling

The advantages of FCFS CPU Process Scheduling are:

  1. In order to allocate processes, it uses the First In First Out queue.
  2. The FCFS CPU Scheduling Process is straight forward and easy to implement.
  3. In the FCFS situation pre emptive scheduling, there is no chance of process starving.
  4. As there is no consideration of process priority, it is an equitable algorithm.

Disadvantages of FCFS CPU Process Scheduling

The disadvantages of FCFS CPU Process Scheduling are:

  • FCFS CPU Scheduling Algorithm has Long Waiting Time
  • FCFS CPU Scheduling favors CPU over Input or Output operations
  • In FCFS there is a chance of occurrence of Convoy Effect
  • Because FCFS is so straight forward, it often isn't very effective. Extended waiting periods go hand in hand with this. All other orders are left idle if the CPU is busy processing one time-consuming order.

Problems in the First Come First Serve CPU Scheduling Algorithm

Example

Non Pre Emptive Approach

Now, let us solve this problem with the help of the Scheduling Algorithm named First Come First Serve in a Non Preemptive Approach.

Gantt chart for the above Example 1 is:

FCFS Scheduling Algorithms in OS (Operating System)

Turn Around Time = Completion Time - Arrival Time

Waiting Time = Turn Around Time - Burst Time

Solution to the Above Question Example 1

S. No Process ID Arrival Time Burst Time Completion Time Turn Around Time Waiting Time
1 P 1 A 0 9 9 9 0
2 P 2 B 1 3 12 11 8
3 P 3 C 1 2 14 13 11
4 P 4 D 1 4 18 17 13
5 P 5 E 2 3 21 19 16
6 P 6 F 3 2 23 20 18

The Average Completion Time is:

Average CT = ( 9 + 12 + 14 + 18 + 21 + 23 ) / 6

Average CT = 97 / 6

Average CT = 16.16667

The Average Waiting Time is:

Average WT = ( 0 + 8 + 11 + 13 + 16 + 18 ) /6

Average WT = 66 / 6

Average WT = 11

The Average Turn Around Time is:

Average TAT = ( 9 + 11 + 13 + 17 + 19 +20 ) / 6

Average TAT = 89 / 6

Average TAT = 14.83334

This is how the FCFS is solved in Non Pre Emptive Approach.

Now, let us understand how they can be solved in Pre Emptive Approach

Pre Emptive Approach

Now, let us solve this problem with the help of the Scheduling Algorithm named First Come First Serve in a Pre Emptive Approach.

In Pre Emptive Approach we search for the best process which is available

Gantt chart for the above Example 1 is:

FCFS Scheduling Algorithms in OS (Operating System)
S. No Process ID Arrival Time Burst Time Completion Time Turn Around Time Waiting Time
1 P 1 A 0 9 23 23 14
2 P 2 B 1 3 8 7 4
3 P 3 C 1 2 3 2 0
4 P 4 D 1 4 15 14 10
5 P 5 E 2 3 11 9 7
6 P 6 F 3 2 5 2 0

Semaphores in OS (Operating System)

To get rid of the problem of wasting the wake-up signals, Dijkstra proposed an approach which involves storing all the wake-up calls. Dijkstra states that, instead of giving the wake-up calls directly to the consumer, producer can store the wake-up call in a variable. Any of the consumers can read it whenever it needs to do so.

Semaphore is the variables which storesthe entire wake up calls that are being transferred from producer to consumer. It is a variable on which read, modify and update happens automatically in kernel mode.

Semaphore cannot be implemented in the user mode because race condition may always arise when two or more processes try to access the variable simultaneously. It always needs support from the operating system to be implemented.

According to the demand of the situation, Semaphore can be divided into two categories.

  1. Counting Semaphore
  2. Binary Semaphore or Mutex

We will discuss each one in detail.


Next TopicCounting Semaphore




The Average Completion Time is:

Average CT = ( 23 + 8 + 3 + 15 + 11 + 5 ) / 6

Average CT = 65 / 6

Average CT = 10.83333

The Average Waiting Time is:

Average WT = ( 14 + 4 + 0 + 10 + 7 + 0 ) /6

Average WT = 35 / 6

Average WT = 5.83333

The Average Turn Around Time is:

Average TAT = ( 23 + 7 + 2 + 14 + 9 +2 ) / 6

Average TAT = 57 / 6

Average TAT = 9.5

This is how the FCFS is solved in Pre Emptive Approach.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA