Professional Documents
Culture Documents
Mod 2
Mod 2
Current
Task
MASTER
CPU
No context switching
after this point
1. Problem of FCFS
Draw the Gantt chart of the FCFS scheduling system and also calculate the
following parameters.
a.) the total and average turn around time
b.) The total and average waiting time
Arrival Time Burst Time
Process
(AT) (msec) (BT) (msec)
P1 0 5
P2 1 3
P3 2 8
P4 3 6
Process Arrival Burst Complete Turn Around Waiting
Solution Time (AT) Time(BT) Time (CT) time (TAT) Time (WT)
CT-AT TAT-BT
P1 0 5 5 5 0
P2 1 3 8 7 4
P3 2 8 16 14 6
P4 3 6 22 19 13
At t=0 only the process P1 has started and executing
Total TAT = 5+7+14+19= 45msec
At t=5 P1 completed the execution, Avg. TAT = 45/4= 11.25 msec
P2 starts at 1st sec, P3 at 2nd sec and P4 at 3rd sec.
Total WT= 0+4+6+13= 23msec
Avg. WT = 23/4= 5.75 msec
Gantt Chart
0 5 8 16 22
P1 P2 P3 P4
Advantages & Disadvantages of FCFS
Advantage of FCFS:
✓Easy to implement.
✓ It is very simple.
✓ First come, first served
✓ Easy to understand
Drawback of FCFS:
❖Trouble some for time sharing systems.
❖The average waiting time is very high, this may impact on the performance of the CPU.
❖The process will run until it finishes.
❖Short processes which are at the back of the queue have to wait for the long process at the
front to finish
b. Shortest Job First (SJF)/ Shortest Process First(SPF)/ Run-To-Completion
• In which, the tasks with the shortest execution time are executed first.
• It requires the knowledge of the service time for each process.
• Optimal for minimizing queueing time, but impossible to implement.
Tries to predict the process to schedule based on previous history.
1. Draw the Gantt chart of the SJF (Non-Preemptive)scheduling system and also
calculate the following parameters.
a.) the total and average turn around time
b.) The total and average waiting time
0 7 8 12 16
P1 P3 P2 P4
Advantages & Disadvantages of SJF
Advantages
• It can give minimum average waiting time.
• Its Simple.
• It is suitable for very little time processes.
Drawbacks
✓If short processes are continually added, the processes which
require a long time to run will starve.
✓The total execution time of a job must be known before execution.
a. Round Robin/FIFO (First In, First Out) Scheduling
No Priority for the task.
key
High q Common time slices for
=PREEMPTION
each task. If the time slice
over, preempts the task
Q = Quantum
✓ It implements a FIFO queue that stores ready processes (processes ready to be executed).
✓ Processes are added to the queue at the end of the queue.
✓ In the FIFO system, all processes are treated equally regardless of their workload or interactivity.
✓ Each process in the FIFO queue is allocated an equal time slice.
✓ An interrupt is generated at the end of each of these intervals to start the pre-emption process.
✓ If a process that is currently running isn’t finished executing by the end of its allocated time slice, it is
preempted and returned to the back of the queue to complete executing the next time its turn comes around.
✓ If a process finishes running before the end of its allocated time slice, the process voluntarily releases the
processor, and the scheduler then assigns the next process of the FIFO queue to the processor.
1. Draw the Gantt chart of the Round Robin scheduling system and also calculate
the following parameters.
a.) the total and average turn around time
b.) The total and average waiting time
Solution
Process Arrival Burst Complete Turn Around Waiting Time
Solution Time (AT) Time(BT) Time (CT) time (TAT) (WT)
CT-AT TAT-BT
P0 0 7 12 12 5
P1 2 4 11 9 5
P2 4 1 10 6 5
0 3 6 9 10 11 12
P0 P1 P0 P2 P1 P0
Merits & Demerits of Round Robin Scheduling
Merits
✓ Very simple to implement
✓ Strict "first come, first served" nature
✓ It's fair; each job gets an equal shot at the CPU.
Demerits
✓ No Priority for tasks
✓ Unequal Task Lengths
✓ More context switches/Task Switches
✓ More waiting time for not completed tasks
b. Priority (Preemptive) Scheduling
• Every process is assigned a priority.
• The processes with the highest priority always preempt lower priority
processes.
• A running task can be forced to block by the scheduler if a higher
priority task becomes ready to run.
High key
1. Draw the Gantt chart of the priority based (non Preemptive) scheduling
system and also calculate the following parameters.
a.) the total and average turn around time
b.) The total and average waiting time
• Therefore, thread switching does not need to call operating system and
to cause interrupt to the kernel.
• Simple Management : This simply means that creating a thread, switching between
threads and synchronization between threads can all be done without intervention of
the kernel.
• Fast and Efficient : Thread switching is not more expensive than a procedure call.
Disadvantages :
• There is a lack of coordination between threads and
operating system kernel. Therefore, process as whole gets
one time slice irrespective of whether process has one
thread or even 1000 threads within it. It is up to each thread
to relinquish control to other threads.
• User-level threads require non-blocking systems call i.e., a
multithreaded kernel. Otherwise, entire process will be
blocked in the kernel, even if there are runable threads left
in the processes. For example, if one thread causes a page
fault, the process gets blocked.
Three primary thread libraries:
• POSIX Pthreads
• Win32 threads
• Java threads
Kernel Level Threads
• The kernel-level threads are slow and inefficient. For instance, threads
operations are hundred of times slower than that of user-level threads.
• Since kernel must manage and schedule threads as well as processes. It
requires a full thread control block (TCB) for each thread to maintain
information about threads.
Multithreading Models
• Many-to-One
• One-to-One
• Many-to-Many
Many-to-One