Operating System
Operating System
What is a process?
In computing, a process is the instance of a computer program that is being
executed by one or many threads. It contains the program code and its activity.
Depending on the operating system (OS), a process may be made up of multiple
threads of execution that execute instructions concurrently.
Objectives of Process Scheduling Algorithm:
Utilization of CPU at maximum level. Keep the CPU as busy as possible.
Allocation of CPU should be fair.
Throughput should be Maximum. i.e. Number of processes that complete their
execution per time unit should be maximized.
Minimum turnaround time, i.e. time taken by a process to finish execution should be
the least.
There should be a minimum waiting time and the process should not starve in the
ready queue.
Minimum response time. It means that the time when a process produces the first
response should be as less as possible.
What are the different terminologies to take care of in any CPU Scheduling
algorithm?
Arrival Time: Time at which the process arrives in the ready queue.
Completion Time: Time at which process completes its execution.
Burst Time: Time required by a process for CPU execution.
Turn Around Time: Time Difference between completion time and arrival time.
Turn Around Time = Completion Time – Arrival Time
Waiting Time(W.T): Time Difference between turn around time and burst time.
Waiting Time = Turn Around Time – Burst Time
What are the different types of CPU Scheduling Algorithms?
There are mainly two types of scheduling methods:
● Preemptive Scheduling: Preemptive scheduling is used when a process
switches from running state to ready state or from the waiting state to the
ready state.
● Non-Preemptive Scheduling: Non-Preemptive scheduling is used when a
process terminates , or when a process switches from running state to
waiting state
1. First Come First Serve:
FCFS considered to be the simplest of all operating system scheduling algorithms.
First come first serve scheduling algorithm states that the process that requests the
CPU first is allocated the CPU first and is implemented by using FIFO queue.
Characteristics of FCFS:
Easy to implement
First come, first serve method
Disadvantages of FCFS:
Shortest job first (SJF) is a scheduling process that selects the waiting process
with the smallest execution time to execute next. This scheduling method may or
may not be preemptive. Significantly reduces the average waiting time for other
processes waiting to be executed. The full form of SJF is Shortest Job First.
Characteristics of SJF:
● Shortest Job first has the advantage of having a minimum average waiting
time among all operating system scheduling algorithms.
● It is associated with each task as a unit of time to complete.
● It may cause starvation if shorter processes keep coming. This problem
can be solved using the concept of ageing.
Disadvantages of SJF:
● One of the demerit SJF has is starvation.
● Many times it becomes complicated to predict the length of the upcoming
CPU request
What is Starvation?
Starvation or indefinite blocking is a phenomenon associated with the Priority
scheduling algorithms, in which a process ready for the CPU (resources) can wait to
run indefinitely because of low priority. In a heavily loaded computer system, a
steady stream of higher-priority processes can prevent a low-priority process from
ever getting the CPU. There have been rumors that in 1967 Priority Scheduling was
used in IBM 7094 at MIT, and they found a low-priority process that had not been
submitted till 1973.
4. Priority Scheduling:
Preemptive Priority CPU Scheduling Algorithm is a pre-emptive method of CPU
scheduling algorithm that works based on the priority of a process. In this algorithm,
the editor sets the functions to be as important, meaning that the most important
process must be done first. In the case of any conflict, that is, where there is more
than one process with equal value, then the most important CPU planning algorithm
works on the basis of the FCFS (First Come First Serve) algorithm.
One of the most common demerits of the Preemptive priority CPU scheduling
algorithm is the Starvation Problem. This is the problem in which a process has to
wait for a longer amount of time to get scheduled into the CPU. This condition is
called the starvation problem.
How does Preemptive Priority CPU Scheduling Algorithm work?
Step-1: Select the first process whose arrival time will be 0, we need to select that
process because that process is only executing at time t=0.
Step-2: Check the priority of the next available process. Here we need to check for 3
conditions.
if priority(current_process) > priority(prior_process) :- then execute the current
process.
if priority(current_process) < priority(prior_process) :- then execute the prior process.
if priority(current_process) = priority(prior_process) :- then execute the process
which arrives first i.e., arrival time should be first.
Step-3: Repeat Step-2 until it reaches the final process.
Step-4: When it reaches the final process, choose the process which is having the
highest priority & execute it. Repeat the same step until all processes complete their
execution.
Characteristics of Round robin:
● It’s simple, easy to use, and starvation-free as all processes get the
balanced CPU allocation.
● One of the most widely used methods in CPU scheduling as a core.
● It is considered preemptive as the processes are given to the CPU for a
very limited time.
Shortest remaining time first is the preemptive version of the Shortest job first
which we have discussed earlier where the processor is allocated to the job closest
to completion. In SRTF the process with the smallest amount of time remaining until
completion is selected to execute.
Characteristics of Shortest remaining time first:
● SRTF algorithm makes the processing of the jobs faster than SJF
algorithm, given it’s overhead charges are not counted.
● The context switch is done a lot more times in SRTF than in SJF and
consumes the CPU’s valuable time for processing. This adds up to its
processing time and diminishes its advantage of fast processing.
Advantages of SRTF:
● In SRTF the short processes are handled very fast.
● The system also requires very little overhead since it only makes a
decision when a process completes or a new process is added.
Disadvantages of SRTF:
● Like the shortest job first, it also has the potential for process starvation.
● Long processes may be held off indefinitely if short processes are
continually added.
Processes in the ready queue can be divided into different classes where each class
has its own scheduling needs. For example, a common division is a foreground
(interactive) process and a background (batch) process. These two classes have
different scheduling needs. For this kind of situation Multilevel Queue Scheduling
is used.
Mid-1 18-19
Q1.What are the 3 main purpose of an operating system
3. User Interface: Operating systems provide ways for you to interact with your
computer, whether through clicking icons on a screen or typing commands, making it
user-friendly and accessible for various tasks.
Q2.How does the distinction between kernel mode and user mode function as
a rudimentary form of protection (security) system
Q3.List five services provided by an operating system and explain how each
creates convenience for users. In which cases it would be impossible for user
level programs to provide these services?
Answer:
1. Program execution - the operating system will schedule on behalf of the user.
This service could not be handled by the user because you need access to the
hardware.
2. I/O operations - This makes it easy for users to access I/O streams. This means
the user does not need to know the physical access of data in the machine. If there
were not interface provided the user could not do this on their own.
3. File-system manipulation - This means the user does not need to worry about
accessing and updating the file system table. Such access is best handled by the
operating system because of this complexity.
5. Error detection - If there is some error on one of the lower levels the user is
notified so that they can take action. If there is no memory left on the heap for
instance. The user could not do this because it is simply too much work for the user.
Q4.Why do some systems store the operating system in firmware while others
store it on disc?(2)
A:For certain devices, such as handheld PDAs and cellular telephones, a disk with a
file system may not be available for the device. In this situation, the operating system
must be stored in firmware.
Q5:Describe the difference between Short term,medium term and long term
scheduling.
Medium-term
Basis Short-Term Scheduler Long-Term Scheduler
Scheduler
4. Usage in
time- sharing
It is minimal in the It is a part of the It is almost absent or minimal in a
system
time-sharing system. time-sharing system. sharing system.
sharing
system
Program Process
Program is a passive entity as it resides in the Process is a active entity as it is created during execution and
secondary memory. loaded into the main memory.
Program exists at a single place and continues to Process exists for a limited span of time as it gets terminated
exist until it is deleted. after the completion of task.
Program has two logical components: code and In addition to program data, a process also requires additional
data. information required for the management and execution.
MID 2(18-19)
Q1:Which of the following scheduling algorithms could result in
starvation?justify your answer i)First come first serve ii)Shortest Job First
iii)Round Robin iv)Priority
1.In First Come First Serve(FCFS) if a process with a very large Burst Time comes
before other processes, the other process will have to wait for a long time but it is
clear that other process will definitely get their chance to execute, so it will not suffer
from starvation.
2.In Round Robin there is a fixed time quant and every process will get their chance
to be executed, so no starvation is here.
3.In Priority based scheduling if higher priority process keep on coming then low
priority process will suffer from starvation.
4.In Shortest Job First(SJF) if process with short process time keep on coming
continuously then process with higher burst time will do wait and suffer from
starvation.
Additional
5.In Shortest remaining time first(SRTF) process with shortest burst time will
execute first because this process with high burst time may suffer from starvation.
Q3:What are the two differences between user level threads and kernel level
threads?Under what circumstance is one type better than the others?
If a process having high priority If a process with a long burst time is running
Starvation frequently arrives in the ready queue, a CPU, then later coming process with less CPU
low priority process may starve. burst time may starve.
Mid 1 19-20
1. Hand Written
2.Banker's algorithm (porayni)
Final exam 18-19
1. a).We have stressed the need for an operating system to make efficient use
of the computing
hardware. When is it appropriate for the operating system to forsake this
principle and to
"waste" resources? Why is such a system not really wasteful?
b) Why do some systems store the operating system in firmware, while others
store it on disk?
c)How does the distinction between kernel mode and user mode function as a
rudimentary form
of protection (security) system?
c) List five services provided by an operating system and explain how each
creates convenience for users.
ANS:Solved in 19-20 Final
2. a) Direct memory access is used for high-speed I/O devices in order to avoid
increasing the CPU's execution load.
i) How does the CPU interface with the device to coordinate the transfer?
ii) The CPU is allowed to execute other programs while the DMA controller is
transferring
data. Does this process interfere with the execution of the user programs? If
so, describe what forms Of interference are caused.
ANS:
i) CPU Interface with DMA for Data Transfer Coordination
- Bus Contention: DMA monopolises system bus, causing delays for CPU and other
devices.
- Memory Bandwidth: DMA consumes memory bandwidth, slowing down user
program access.
- Interrupt Overhead: CPU handles interrupts from DMA, adding processing
overhead.
- Priority Handling: DMA may delay user programs to prioritise transfers, affecting
responsiveness.
b) What are the two essential parts of a process? How is a process different
from a program?
Two essential parts of a process are:
Process Control Block (PCB): The PCB is a data structure maintained by the
operating system for each process. It contains various pieces of information about
the process, including its current state, program counter, CPU registers, memory
allocation, process ID, priority, etc. The PCB represents the dynamic part of the
process, as it changes with the state of the process during its execution.
c) Consider the following set of processes. with the length of the CPU burst
given in milliseconds:
1
The processes are assumed to have arrived in the order P1, P2, P3, P4, P5 all
at time O.
i) Draw four Gantt charts that illustrate the execution of these processes using
the
following scheduling algorithms: FCFS, SJF, non preemptive priority (a large
priority
number implies a higher priority), and RR (quantum = 2)
ii) What is the turnaround time of each process for each of the scheduling
algorithms
iii) What is the waiting time of each process for each of these scheduling
algorithms?
iv) Which of the algorithms results in the minimum average waiting time (over
all
processes)?
i) Gantt Charts
1. FCFS (First Come First Serve):
| P1 | P2 | P3 | P4 | P5 |
0 2 3 11 15 20
| P2 | P1 | P4 | P5 | P3 |
0 1 3 7 12 17
| P1 | P2 | P4 | P5 | P3 |
0 2 3 7 12 20
| P1 | P2 | P3 | P4 | P5 | P1 | P3 | P5 | P3 |
0 2 3 5 7 9 11 13 15 17
- FCFS: P1 = 0, P2 = 0, P3 = 6, P4 = 3, P5 = 7
- SJF: P1 = 0, P2 = 0, P3 = 1, P4 = 2, P5 = 7
- Non-preemptive Priority: P1 = 0, P2 = 0, P3 = 6, P4 = 3, P5 = 7
- RR: P1 = 7, P2 = 0, P3 = 9, P4 = 5, P5 = 7
So, SJF has the minimum average waiting time over all processes.