0% found this document useful (0 votes)
16 views11 pages

Lab 3

Uploaded by

prabidushk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views11 pages

Lab 3

Uploaded by

prabidushk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Lab 3

Implementation of CPU Scheduling: i) FCFS, ii)


Shortest Job First iii) Shortest Remaining Time
First and iv) Priority based
1. First Come First Serve Scheduling (FCFS Scheduling)

• i) Jobs are executed on first come and first serve basis


• ii) It is a non pre-emptive scheduling algorithm
• iii) It is easy to understand and implement
• iv) Its implementation is based on first in first out (FIFO) queue
• v) It is poor in performance as average waiting time is high
Algorithm:

• 1. Start the program.


• 2. Get the number of processes and their burst time.
• 3. Initialize the waiting time for process 1 and 0.
• 4. Process for(i=2;i<=n;i++),wt.p[i]=p[i-1]+bt.p[i-1].
• 5. The waiting time of all the processes is summed then average value
time is calculated.
• 6. The waiting time of each process and average times are displayed
• 7. Stop the program
2. Shortest Job First Scheduling (SJF Scheduling)

• i) It is a non pre-emptive scheduling algorithm


• ii) It is best approach to minimize waiting time
• iii) It is easy to implement in batch systems where required CPU time
is known in advance
• iv) Impossible to implement in interactive systems where required
CPU time is not known
• v) The processor should know in advance how much time process will
take
Algorithm:

• 1. Start the program. Get the number of processes and their burst time.
• 2. Initialize the waiting time for process 1 as 0.
• 3. The processes are stored according to their burst time.
• 4.The waiting time for the processes are calculated as follows:
• for(i=2;i<=n;i++), wt.p[i]=p[i=1]+bt.p[i-1].
• 5. The waiting time of all the processes summed and then the average
time is calculate
• 6. The waiting time of each processes and average time are displayed.
• 7. Stop the program.
3. Shortest Remaining time first (SRTF)
i) It is a pre-emptive scheduling algorithm.
ii) It aims to minimize waiting time by choosing the process with the
smallest remaining processing time.
iii) It is more appropriate for interactive systems compared to SJF as it
allows for dynamic adjustments when shorter processes arrive.
iv) Implementation is complex as it requires continuous recalculation of
remaining times and frequent context switching.
v) The processor needs precise and updated knowledge of remaining
CPU time, which can be challenging to maintain accurately.
Algorithm:
1. Get the number of process and their burst time.
2. Traverse until all process gets completely executed.
i. Find process with minimum remaining time at every single time lap.
ii. Reduce its time by 1.
iii.Check if its remaining time becomes 0
iv. Increment the counter of process completion.
v. Completion time of current process = current_time +1;
vi. Calculate waiting time for each completed process.
vii.wt[i]= Completion time - arrival_time-burst_time
viii.Increment time lap by one.
3. The waiting time for each process are displayed.
4. Stop the program.
3. Priority Scheduling

• i) SJF scheduling is special case of priority scheduling


• ii) Priority is associated with each process
• iii) CPU is allotted to the process with the highest priority
• iv) For the case of equal priority, processes are scheduled on the basis
of FCFS
• v) It is a non pre-emptive scheduling
• vi) Priority can be decided based on memory or time requirements or
any other resource requirements
Algorithm:

• 1. Start the program.


• 2. Read burst time, waiting time, turn around time and priority.
• 3. Initialize the waiting time for process 1 and 0.
• 4. Based up on the priority process are arranged
• 5. The waiting time of all the processes is summed and then the
average waiting time
• 6. The waiting time of each process and average waiting time are
displayed based on the priority.
• 7. Stop the program.
Assignment Questions:

1.Write a C/C++ program to simulate the following non


preemptive CPU scheduling algorithms to find
average turnaround time and average waiting time.
(Provide user inputs)
a)FCFS
b)SJF
c)SRTF
d)Priority Based
Sample Input:

Process Arrival Time Burst Time Priority

P0 0 4 2
P1 1 3 3
P2 2 1 4
P3 3 5 5
P4 4 2 5

You might also like