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

Sheet 5

FCFS Scheduling in OS

It is the simple CPU scheduling algorithm. The criteria of this algorithm are the
process that requests the CPU first or the process which enters ready queue first,
served first. If a process requests then it is loaded by short-term scheduler into the
ready queue. The process is then connected to the CPU by a dispatcher for
execution. It is called the FCFS scheduling in operating system.

The main disadvantage of this algorithm is aging. Due to this problem, big jobs
have to wait for the CPU for a long time.

Q1:

First of all, we have to calculate the waiting time of each process.


Waiting Time = Starting Time - Arrival Time
Waiting time of
P1 = 0
P2 = 5 - 0 = 5 ms
P3 = 29 - 0 = 29 ms
P4 = 45 - 0 = 45 ms
P5 = 55 - 0 = 55 ms
Average Waiting Time = Waiting Time of all Processes / Total Number of Process
Therefore, average waiting time = (0 + 5 + 29 + 45 + 55) / 5 = 25 ms

Shortest Remaining Time First(SRTF Scheduling)

This algorithm is the preemptive scheduling algorithm, in which the short-term


scheduler always chooses the process that has the shortest remaining processing
time. When the new process joins the ready queue, the short-term scheduler
compares the time of the executing process and the new process.

If the new process having the least CPU burst time, the scheduler selects that job
and connect to the CPU, otherwise, continue in the old process.

Average Waiting Time

First of all, we have to find the waiting time for each process.
Waiting Time of process
P1 = 0ms
P2 = (3 - 2) + (10 - 4) = 7ms
P3 = (4 - 4) = 0ms
P4 = (15 - 6) = 9ms
P5 = (8 - 8) = 0ms
Therefore, Average Waiting Time = (0 + 7 + 0 + 9 + 0) / 5 = 3.2ms

Round Robin(RR) Scheduling

It is a preemptive scheduling algorithm. It is designed typically for time-sharing


systems. In this algorithm, the CPU switches between the processes when the time
quantum is expired, the CPU switches to another job. In this algorithm, the ready
queue is a circular queue. The time quantum dependent on the operating system.

Advantage

The main advantage of this algorithm is easy to implement, and it is simple.


Disadvantage

The drawback of this algorithm is particularly troublesome for the time-sharing


system, and another drawback is average waiting time is very high, this may
impact on the performance of the CPU.

Average Waiting Time

For finding Average Waiting Time, we have to find out the waiting time of each
process.
Waiting Time of
P1 = 0 + (15 - 5) + (24 - 20) = 14ms
P2 = 5 + (20 - 10) = 15ms
P3 = 10 + (21 - 15) = 16ms
Therefore, Average Waiting Time = (14 + 15 + 16) / 3 = 15ms

Shortest Job First(SRTF) Scheduling

The criteria of this algorithm in which the process having the smallest CPU burst
time, CPU is assigned to the process next, if two processes have the same CPU
burst time, FCFS is used to break the tie.

Advantage

It has least average waiting time, average turnaround time and average response
time.
Disadvantage

1. Knowing the length of the next CPU burst time is difficult.


2. It is an optimal algorithm. It cannot be implemented by at the level of short-
term CPU scheduling.

New processes added to the tail of the ready queue. The CPU scheduler picks the
first process from the ready queue, set a timer to interrupt after one time-quantum,
and dispatches the process.

One of the two things will happen in this algorithm.

If the process may have a CPU burst time is less than one time-quantum, then
process releases the CPU voluntarily. The scheduler will then proceed to the next
process in the ready queue.

Otherwise, if the CPU burst time of the concurrently running process is longer than
one time-quantum, then the process will be put at the tail of the ready queue. The
CPU scheduler will then select the next process.

Q2:

Average Waiting Time

We will apply the same formula to find average waiting time in this problem. Here
arrival time is common to all processes(i.e., zero).
Waiting Time for
P1 = 3 - 0 = 3ms
P2 = 34 - 0 = 34ms
P3 = 18 - 0 = 18ms
P4 = 8 - 0 = 8ms
P5 = 0ms
Now, Average Waiting Time = (3 + 34 + 18 + 8 + 0) / 5 = 12.6ms

Priority Scheduling in OS

Generally, priorities are of two types. One is the internal priority, and the second is
the external priority. External priority means it is external to the operating system.
The CPU is allocated to process with the highest priority.

The priorities use some measurable quantities to compute the priority of a process.
For example, time limits, memory requirements, the number of open files, and the
ratio of average I/O burst to an average CPU burst have used in computing
priorities.

Disadvantage

The major problem with priority scheduling is starvation. Starvation means only
high priority processes are executing, but low priority jobs are waiting for the CPU
for a long time.

Average Waiting Time

First of all, we have to find out the waiting time of each process.
Waiting Time of process
P1 = 3ms
P2 = 13ms
P3 = 25ms
P4 = 0ms
P5 = 9ms
Therefore, Average Waiting Time = (3 + 13 + 25 + 0 + 9) / 5 = 10ms

You might also like