L-2.3: First Come First Serve(FCFS) CPU Scheduling Algorithm with Example - YouTube

Channel: Gate Smashers

[0]
Hello Friends, welcome to Gate smashers
[2]
The topic is FCFS First come first serve scheduling algorithm
[6]
Let's understand with the numerical
[8]
So in numerical first of all we are given the process number P1, P2, P3, P4
[13]
Means 4 processes are here, along with arrival time... Means which process arrived at what time
[21]
Burst time... You can call it execution time also
[27]
This is time duration.. Means every process told how much time it'll take to get executed
[34]
There's no importance of its dimensions here if it's 2 mins, seconds or hours
[42]
It can be any value... So our main motive here is how FCFS works
[48]
So FCFS's working criteria is arrival time
[51]
Means it checks the arrival time, we'll serve the one which came first
[58]
And mode is non preemptive... means if a process arrived and I gave it to CPU
[65]
Means CPU started to execute that process, it won't stop in between, it'll get completely executed
[73]
And after execution it'll get terminated
[76]
So let's see how we'll solve this numerical
[81]
So first we'll check the arrival time of all the processes I.e. 0... 1... 5... 6
[91]
Now here I have to use gantt chart
[94]
This chart will help you in solving the numerical in the easiest way
[99]
So here time starts from 0
[105]
Now at 0, first you have to check which process has arrived
[111]
Means which process arrived at 0 from all these
[114]
So you can see clearly here, P1 arrived at 0 So there's no any other process left
[121]
Other than P1 there's no process which came at 0 So simply just bring it here
[127]
Bringing P1 here means we started executing P1 on the CPU
[133]
P1 says it'll take 2 unti of time to execute properly
[140]
So we'll run it for complete 2 units without any break
[146]
Non Preemptive means that we'll not stop the process in between
[151]
Now P1 got executed up to 2 and after that P1 left from here
[156]
Means you can say that P1 got executed at time 2
[161]
Now we are at time 2... means let's say the time is of 2'O clock
[170]
Now check again which process has already arrived
[176]
Let's say if you'll see P2 then P2 has arrived at 1
[181]
1 must be occurred between 0 and 2 Means P2 has already arrived in the ready queue
[192]
Is P3 arrived?.. No P3 will arrive at 5... but we are still at 2
[199]
Means P3 and P4 haven't arrived
[202]
But P2 has arrived and sitting in the ready queue
[206]
Now take out P2 from the ready queue and bring it here... Means execute it over the CPU
[213]
For how much time?... it said already that it'll take 2 unit of time,
[218]
so we'll execute it here for up to 2 unit of time
[222]
so here my time became 4 and P2 also got executed from here
[228]
Now check my time here, first we've to check the time here i.e. 4'O clock
[234]
Now at 4"o clock check which process has arrived
[239]
P3 will arrive at 5 and P4 will arrive at 6 And there's no process other than these two
[246]
So the important point here is that you can't do anything at 4
[253]
So it means, for one unit of time i.e. 4 - 5, CPU is idle
[261]
Idle means CPU don't have any process to execute So simply we made CPU Idle from 4 to 5
[269]
Now P3 arrived at 5'O clock SO we'll start executing P3
[277]
We executed P3 here for up to 3 time unit i.e. up to 8
[287]
Now P3 also left from here, now time is 8 And P4 arrived at 6, and 6 has already passed
[297]
Means P4 has already arrived in the ready queue So take out P4 from the ready queue and execute it
[306]
So here, simple... The process which came first, we have to take it out of the ready queue
[313]
So P4's time is 4... so 8 + 4 i.e. 12 So at time 12 all the processes got executed
[324]
P1, P2, P3, P4... All four have been executed
[328]
So many times they ask what is the time at which they all got executed... so you can write 12
[339]
Now we have to write completion time of all the processes
[343]
So here check when P1 got executed We have to check its right hand side
[350]
At 2... So P1 got completed at 2 P2 at 4... P3 at 8...
[358]
you have to check below in the right hand side
[361]
P4 got executed at 12... So simply write here, this is the time at which P1... P2... P3... P4 got executed
[370]
Now we've to find out TAT... i.e. Turn around time TAT is that for how much time a process stayed in the system
[381]
So it means... when it got completed and when it arrived, that's the TWT i.e. TWT = CT - AT
[391]
So you can find it easily... 2 - 0 i.e. 2 4 - 1 i.e. 3... 8 - 5 i.e. 3..... 12 - 6 i.e. 6
[403]
So this is the time turn around Now it's WT i.e. waiting time
[410]
WT is... how much was the useful time and how much time it had spent there
[417]
Now TWT means 2... Means P1 stayed for 2 unit of time
[424]
and how to know how much time it was supposed to stay.... Through burst time
[429]
Means useful time is the burst time but for how time it stayed... that's turnaround time
[437]
So TWT - BT... then it'll be waiting time So waiting time became 2 - 2 i.e. 0
[450]
3 - 2 = 1....... 3 - 3 = 0 6 - 4 = 2... so this is the waiting time
[458]
Means P1 stayed in the system for 2 unit time
[463]
And it was supposed to stay for 2 time, then obviously waiting time arrived 0
[467]
But if you'll see in case of P2... why 1 arrived?
[471]
P2 stayed for 3 time unit, but it was supposed to stay for 2 time only
[477]
So if you'd see carefully then P2 arrived at 1 but it git its turn at 2
[487]
So that's why it had to wait for its 1 unit time there
[492]
So next question they can ask from here is response time
[497]
Response time = time at which the process got the CPU first time - arrival time
[508]
Now When P1 got the CPU first time?... Now check in gantt chart when P1 got the CPU first
[515]
Because you can find out everything easily through gantt chart
[520]
So P1 got CPU at 0 ... now we've to check the left side, So P1 got CPU at 0 and it arrived at 0... So 0 - 0 = 0
[533]
Next is the P2... P2 got the CPU first time at 2 And P2 arrived at 1, so 2 - 1 i.e. 1
[545]
P3... P3 got the CPU first time at 5 And P3 came at 5 first... So 5 - 5 i.e. 0
[555]
P4 got the CPU first time at 8... but it arrived at 6, so 8 - 6 i.e. 2
[563]
Let me tell you a point here that in case of non preemptive... Because FCFS is non preemptive
[570]
so there's no benefit of calculating the response time in this case
[573]
,because response time will always come equal to waiting time
[578]
This question of response time will come more in case of round robin, in SJF...
[583]
Means in the preemptive case more But still we solved it here
[589]
No one will ask you more than this about different times
[593]
yeah but next they can ask what is the average turnaround time
[599]
So you can calculate average turnaround time... i.e.. 14 divide by total no. of processes 4
[609]
And how to calculate average waiting time... how would you calculate average waiting time
[613]
Just add all of that... 3 divided by no. of process i.e. 4
[619]
So it comes out to be 0.75 and it comes out to be 3.5
[626]
So this is the average turnaround time and waiting time
[630]
So this is all about the FCFS
[632]
Thank You!!