Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

SEMESTER PROJECT

Operating system

SUBMITTED BY :
MARYAM WASEEM (2022 BSE-059)

IQRA SHAHZAD (2022- BSE – 078)

SUBMITTED TO :
DR. MEHREEN SIRSHAR
TOPIC:

SCHEDULING ALGORITHM

FCFS Scheduling Algorithm: FCFS (First-Come-First-Serve) is one of the simplest


scheduling algorithms used in computer operating systems and job scheduling. It follows the

principle of "first come, first served," meaning that the process that arrives first is the one that

gets executed first.

Here's how the FCFS scheduling algorithm works:

1. Arrival of processes:

 Processes arrive in the ready queue in the order they come.

 The process that arrives first is the one that will be scheduled

2. Execution:

 When the CPU is available, the process at the front of the ready queue is selected for

execution.

 The selected process runs until it completes its execution or is interrupted by another

process with a higher priority.

3.ComPletion:

 Once a process completes its execution, the next process in the ready queue is selected

for execution.

4. Waiting time:

The waiting time for a process is the total time it spends waiting in the ready

queue before getting the Cu for execution.

5. Turnaround time:
Turnaround time is the total time taken by a process to complete its execution,

including both waiting time and execution time.

6. Advantages:

Simple and easy to understand.

No starvation (every process gets a chance to execute).

7. Disadvantage:

 poor in terms of turnaround time, especially if a long process arrives first, as

shorter processes have to wait.

 The "convoy effect" can occur, where shorter processes get stuck waiting behind

a long process.

Example:

 Consider three processes, P1, P2, and P3, arriving in the order P1, P2, P3.

 If the burst times for P1, P2, and P3 are 10, 6, and 8 units, respectively, the execution

order would be P1, P2, P3.

 Turnaround Time = Burst Time + Waiting Time

Process | Arrival Time | Burst Time | Completion Time | Turnaround Time |

Waiting Time

-------------------------------------------------------------------------------

 P1 |0 | 10 | 10 | 10 |0

 P2 |0 |6 | 16 | 16 | 10

 P3 |0 |8 | 24 | 24 | 16

In the example, the completion time for each process is calculated as the sum of

the burst times of all previous processes. The turnaround time is the time from

arrival to completion, and waiting time is the difference between turnaround

time and burst time.


REAL LIFE EXAMPLE:

1) Buying a movie ticket at the counter

Buying a movie ticket at the counter is another real-life example of FCFS (First
Come First Serve) scheduling. Here's a scenario to illustrate how FCFS works in
this context:
Imagine you arrive at a movie theater to purchase a ticket. There's a single ticket
counter, and several people are waiting in line to buy tickets. Each person in the
line is served in the order they arrived.
1. Person A: Arrives at the counter at 5:00 PM.
2. Person B: Joins the queue behind Person A at 5:05 PM.
3. Person C: Joins the queue behind Person B at 5:10 PM.
In this FCFS scenario:
 The ticket seller serves Person A first because they were the first in line.
 Once Person A completes the purchase, the ticket seller serves Person B
next.
 Finally, after Person B completes the purchase, Person C is served.

The order of service strictly follows the order in which people arrived at the ticket
counter. This ensures fairness, as individuals who queued up earlier are served
before those who arrived later. FCFS is a straightforward and easy-to-understand
scheduling approach, making it suitable for scenarios like buying movie tickets
where fairness in service order is important.
2) Printer queue
In a real-life example of a printer queue using the FCFS (First Come First Serve)
scheduling algorithm, imagine an office environment where multiple users share
a single printer. Each user sends print jobs to the printer, and the jobs are
processed in the order they are received.

Let's consider a scenario with three users, each submitting a print job to the
printer:

1. User A submits a print job at 10:00 AM.


2. User B submits a print job at 10:05 AM.
3. User C submits a print job at 10:10 AM.
The printer queue would follow the FCFS principle, and the order of print jobs in
the queue would be:
1. Print Job from User A (Submitted at 10:00 AM)
2. Print Job from User B (Submitted at 10:05 AM)
3. Print Job from User C (Submitted at 10:10 AM)
Now, the printer starts processing the print jobs based on the FCFS scheduling
algorithm:
1. The printer begins printing the job from User A.
2. Once the job from User A is completed, the printer moves on to the job
from User B.
3. Finally, the printer processes the print job from User C.
This order ensures that print jobs are serviced in the order they are received,
which is the essence of the FCFS scheduling algorithm in the context of a
printer queue.
Reference:
"Operating System Concepts" by Abraham Silberschatz, Peter Baer Galvin, and Greg Gagne

You might also like