0% found this document useful (0 votes)
10 views

Operating System Unit 1 2 3

The document provides an overview of operating systems (OS), defining their role as intermediaries between user applications and hardware, and outlining their goals such as user convenience and efficiency. It discusses various types of OS, including batch processing, multiprogramming, multitasking, and real-time systems, along with their advantages and disadvantages. Additionally, it covers process management, including process attributes, states, scheduling algorithms, and the importance of context switching in optimizing CPU utilization.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Operating System Unit 1 2 3

The document provides an overview of operating systems (OS), defining their role as intermediaries between user applications and hardware, and outlining their goals such as user convenience and efficiency. It discusses various types of OS, including batch processing, multiprogramming, multitasking, and real-time systems, along with their advantages and disadvantages. Additionally, it covers process management, including process attributes, states, scheduling algorithms, and the importance of context switching in optimizing CPU utilization.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 71

Operating System

Note: The ppt content is only for reference. Mistakes may be in the
ppt. So it is advised to go through reference book
Unit 1
What is OS?
• OS stands for operating system
Definition
• It act as interface between user applications
and hardware.
• System program that plays the role of
resource manager.
• Set of utilities to simplify application
development/execution.
• Act like government.
• Examples of Operating Systems are Windows,
Linux, Mac OS, etc.
• Hardware – CPU, Memory , I/O devices.
Goals of OS
• User Convenience- how easily user can interact with hardware
• Efficiency – how good it can utilize resources
• Generally, it is evaluated in terms of throughput.
• Throughput refers to number of tasks executed per second.
• For window OS- primary goal is user convenience while is secondary goal
• In Linux OS- efficiency – primary goal, user convenience – secondary goal
• Other goals –
• reliability,
• portability,
• robustness,
• scalability
Parts of OS
• Generally two parts
• Shell
• Kernel
• OS consists of different modules(system program
• Kernel consists of functions that defines the function of different
modules of OS.
• Right click on file folder empty place has different menus-
(different modules defined)
• Double click, right click has different function defined and are
stored in kernel.
• To reach/interact with kernel we use shell.
• Generally, two ways of shell – GUI or CLI command line.
• Each OS has different kernel
• Different kernel has multiple Shell
• For e.g. windows support both GUI and CLI
• While linux OS support generally CLI
Program Mode of operation
• User Mode
• Kernel Mode
System Call ▪ In user mode, program under execution doesn’t have
• System call is the way by which user whole access to system resource.
program interact with OS. ▪ To define which mode, a mode bit is used.
• Double click – shell -> system call -> ▪ Mode bit – 1 : user mode, 0: kernel mode.
kernel. ▪ If allow every access , virus creation is easily
possible.
• Shell scripting – different commands ▪ In kernel mode , program under execution can
and what they do.
access all resources.
• File- open(), read(), close(), write(), ▪ Also known as privileged mode.
create file,
• Process control- load, execute,
abort, fork, wait =, signal, etc.
• Information- get pid, attributes,
system time and date.
• Device related- read, write, ioctl.
Functions of OS
• Resource Management- mapping hardware resource to multiple applications
running simultaneous.
• Process Management- how to run multiple process on system hardware. (CPU
scheduling)
• Storage Management- how process are stored in secondary memory( File system
(NTFS FAT32)
• Memory Management- How to stored process and bring which process in RAM ( as it
is limited). ( Multi programming/tasking)
• Security and Privacy- ( Authentication / password, user and admin mode, one
program cannot interfere with other program resources).
• Accounting – Task manager
Types of OS
• Batch Processing OS
• Multiprogramming
• Multitasking
• Multiprocessing
• Real Time OS
• Embedded
• Distributed OS
• Generally 3 components- CPU , Memory, I/O.
• OS resides in Main memory (RAM).
Batch Processing
• This type of operating system does not interact with
the computer directly.
• There is an operator which takes similar jobs having
the same requirement and groups them into batches.
• It is the responsibility of the operator to sort jobs with
similar needs
• Only one program reside in main memory , low CPU
utilization
Advantages of Batch Operating System
• Job completion time is known.
• Multiple users can share the batch systems.
Disadvantages of Batch Operating System
• The computer operators should be well known with
batch systems.
• Batch systems are hard to debug.
• The other jobs will have to wait for an unknown time if
any job fails.
Multiprogramming OS
• To increase CPU utilization , in this we allow more
than one program to reside in RAM
• This is also known as Degree of multiprogramming.
It represent how many process reside in Main
memory.
• As we increase DOM, CPU utilization also
increases.
• When any process leaves for I/O , other process is
scheduled to the CPU.
• At a time only process is processed by CPU.
Advantages of Multi-Programming Operating
System
• Multi Programming increases the Throughput of
the System.
• It helps in reducing the response time.
Disadvantages of Multi-Programming Operating
System
• There is not any facility for user interaction of
system resources with the system.
Multitasking OS
• It is also known as pre-emptive version
of Multiprogramming
• It is simply a multiprogramming
Operating System with having facility
of a Round-Robin Scheduling
Algorithm.
• It can run multiple programs
simultaneously.
• But user are unaware of it.
Advantages of Multi-Tasking
Operating System
• Better user responsiveness.
Disadvantages of Multi-Tasking
Operating System
• User interaction is only one at a time.
Multiprocessing OS
• More than one CPU reside in the
system.
• Enhanced Throughput and
robustness is seen.
• Generally, of two types
• Tight coupled (shared ) – each cpu
has common shared memory
• Loose coupled- each cpu has
different memory.
Real Time OS
• OSs serve real-time systems.
• The time interval required to process and respond
to inputs is very small.
• This time interval is called response time.
• Real-time systems are used when there are time
requirements that are very strict like missile
systems, air traffic control systems, robots, etc.
• Generally of two types
• Hard RTOS- strict response time e.g. missile,
airbags system
• Soft RTOS- deadline can be little bit delay e.g.
banking, streaming.
Distributed Operating System
• Various autonomous interconnected
computers communicate with each other
using a shared communication network.
• Independent systems possess their own
memory unit and CPU.
• These are referred to as loosely coupled
systems or distributed systems.
• High availability and robustness
Advantages of Distributed Operating System
• Failure of one will not affect the other network
communication, as all systems are
independent of each other.
• Scalable, and load balanced
Disadvantage
• Synchronization
Embedded OS
• Designed for specific purpose.
• Basically embedded in machine to make them smart.
• E.g. Microwave, AC
• User interaction with OS is minimum.
• Rigid in nature-( once developed cannot be easily
reprogrammed).
Unit 2 – Process Management
What is Process?
• Program under execution is known as Process.
• Initially the program is stored in secondary memory.
• For execution it has to brought in Main memory.
• Process management involves identifying the steps involved in
completing a task, assessing the resources required for each
step, and determining the best way to execute the task.
• Stack- local variables, function
• Heap –dynamic memory allocation
• Data – information
• Text- current activity description
Process Attributes
• A process has the following attributes.
• Process Id: A unique identifier assigned by the operating system.
• Process State: Can be ready, running, etc.
• Program Counter
• List of General-purpose Registers
• Priority Info
• List of files
• List of devices.
• All of the above attributes of a process are also known as the context of the process.
• Every process has its own process control block(PCB), i.e. each process will have a
unique PCB.
• This PCB info is also stored in RAM.
Process State
• A process is in one of the following states:
• New: Newly Created Process (or) being-created process.(App downloaded)
(secondary memory)
• Ready: After the creation process moves to the Ready state, i.e. the process is ready
for execution. (Main memory )
• Run: Currently running process in CPU (only one process at a time can be under
execution in a single processor) (Main memory). (dispatcher)
• Wait (or Block): When a process requests I/O access.(Main memory)
• Complete (or Terminated): The process completed its execution.(out of Main memory)
• Suspended Ready: When the ready queue becomes full, some processes are moved
to a suspended ready state
• Suspended Block: When the waiting queue becomes full.
• When any process changes its state , context switching happen.
Context Switching of Process
• The process of saving the context of one process and loading the context of another process is
known as Context Switching. In simple terms, it is like loading and unloading the process from
the running state to the ready state and vice -versa.
• It is performed by dispatcher . It is small program that perform context switching.
• When Does Context Switching Happen?
• 1. When a high-priority process comes to a ready state (i.e. with higher priority than the running
process).
2. An Interrupt occurs.
3. User and kernel-mode switch (It is not necessary though)
4. Preemptive CPU scheduling is used.
CPU-Bound vs I/O-Bound Processes
• A CPU-bound process requires more CPU time or spends more time in the running
state. An I/O-bound process requires more I/O time and less CPU time. An I/O-bound
process spends more time in the waiting state.
• Process planning is an integral part of the process management operating system. It refers
to the mechanism used by the operating system to determine which process to run next.
The goal of process scheduling is to improve overall system performance by maximizing
CPU utilization, minimizing execution time, and improving system response time.
Scheduling Queue
• Job queue- to store processes of new
state.
• Ready Queue- to store processes of
ready state.
• Device Queue- to store processes of
wait state.
Types of scheduler:
• Long term scheduler(Job): bring job
from new to ready state.
• Short term scheduler (CPU): bring job
from ready to running state.
• Middle term scheduler: from ready to
suspended state.
What are the different
Objectives of Process Scheduling terminologies to take care of in
Algorithm:
•Utilization of CPU at maximum level. Keep
any CPU Scheduling algorithm?
•Arrival Time: Time at which the process arrives in
CPU as busy as possible.
the ready queue.
•Allocation of CPU should be fair.
•Completion Time: Time at which process
•Throughput should be Maximum. i.e.
completes its execution.
Minimum turnaround time, i.e. time taken by •Burst Time: Time required by a process for CPU
a process to finish execution should be the execution.
least. •Turn Around Time: Time Difference between
•There should be a minimum waiting completion time and arrival time.
time and the process should not starve in the Turn Around Time = Completion Time – Arrival
ready queue. Time
•Minimum response time. It means that the •Waiting Time(W.T): Time Difference between
time when a process produces the first turn around time and burst time.
response should be as less as possible. Waiting Time = Turn Around Time – Burst Time
Types of Scheduling
• 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.
FCFS (First Come First Serve)
Criteria:
• Scheduled based on arrival time
• If tie – then prefer process with low
process id.
Type:
• Non-pre-emptive
• To solve question we draw Gantt
chart , that keep tracks of process
order execution.
• It always start with zero
• Ready Queue- P1, P2, P3
TAT= CT- AT
WT= TAT- BT
Response time- first
time it get chances of
CPU
P1= 0
P2= 27
P3= 33
• Convoy Effect :
• If the first process arrived in
system has long burst time, then
all the remaining process waiting
time increases.
• Short term process may have also
to wait long.
• FCFS faces this problem.
Shortest Job First( SJF)
Criteria :
• Burst time or Execution Time
• Tie Breaker- arrival time and process id.
Type:
• Non-preemptive
Advantages of Shortest Job first:
• As SJF reduces the average waiting time thus, it
is better than the first come first serve
scheduling algorithm.
• Disadvantages of SJF:
• One of the demerit SJF has is starvation.
• Not practically implemented as Burst time of
process in advance is unknown.
Shortest Remaining Time First(SRTF)
Criteria :
• Burst time or Execution Time
• Tie Breaker- arrival time and process id.
Type:
• Preemptive (so short process arrives it pre-
empt already running process)
Advantages of Shortest Job first:
• In SRTF the short processes are handled
very fast.
• Disadvantages of SJF:
• One of the demerit SJF has is starvation.
• Not practically implemented as Burst time
of process in advance is unknown.
Note : In case of Pre-emption, waiting and response time
is different while in non-pre-emption it is same.
Priority Based Scheduling
Criteria:
• Based on Priority, we scheduled
processes.
• Mostly priority is unique for each process.
In case tie breaker, question always give
hint.
Type:
• Pre-emptive and Non-preemptive.
• Higher number or small number is given
what priority given in question.
• Starvation problem.
• When Solve using pre-emptive nature.
Starvation and its Counter Measure
• Starvation is the problem that occurs when high priority processes keep executing
and low priority processes get blocked for indefinite time.

• In heavily loaded computer system, a steady stream of higher-priority processes


can prevent a low-priority process from ever getting the CPU.

• In starvation resources are continuously utilized by high priority processes.

• Problem of starvation can be resolved using Aging.

• In Aging priority of long waiting processes is gradually increased.


Round Robin
• Criteria:
• Arrival time + time quantum
• Time quantum is the maximum time for which a process is
assigned the cpu, and after this time cpu is pre-empted from
process.
• In case tie breaker, the process id with lower is preferred.
• E.g.- fielding practices.
Type:
Preemptive.
Note:- Choosing time quantum is very critical. Small- low cpu efficiency, high- low user interaction(fcfs)
Multilevel Queuing Scheduling
• Generally only one scheduling policy
is allowed in the system.
• But in case designer want to opt for
more than one scheduling policy then
we opt for Multilevel Queuing
scheduling policy.
• For example, a common division is
a foreground (interactive) process
and a background (batch) process.
• Generally we do this in two ways:
• Fixed priority preemptive scheduling method-
run all process of high priority and then serve low priority.
Starvation problem
inflexibility
• Time slicing-
Divide the whole cpu into fraction and serve them accordingly.
Multilevel feedback Queuing scheduling
• Multilevel Feedback Queue Scheduling
(MLFQ) CPU Scheduling is like Multilevel
Queue(MLQ) Scheduling but in this process
can move between the queues. And thus, much
more efficient than multilevel queue
scheduling.
• Priorities adjusted dynamically:
• Multiple queues:
Advantages of Multilevel Feedback Queue
Scheduling:
• It is more flexible.
• It allows different processes to move between
different queues. Now let us suppose that queues 1 and 2 follow
• It prevents starvation by moving a process that round robin with time quantum 4 and 8
waits too long for the lower priority queue to the respectively and queue 3 follow FCFS.
higher priority queue.
Q. Consider a system that has a CPU-bound process, which requires a burst time of 40
seconds. The multilevel Feed Back Queue scheduling algorithm is used and the queue time
quantum ‘2’ seconds and in each level it is incremented by ‘5’ seconds. Then how many
times the process will be interrupted and in which queue the process will terminate the
execution?
• Process P needs 40 Seconds for total execution.
• At Queue 1 it is executed for 2 seconds and then interrupted and shifted to queue 2.
• At Queue 2 it is executed for 7 seconds and then interrupted and shifted to queue 3.
• At Queue 3 it is executed for 12 seconds and then interrupted and shifted to queue 4.
• At Queue 4 it is executed for 17 seconds and then interrupted and shifted to queue 5.
• At Queue 5 it executes for 2 seconds and then it completes.
• Hence the process is interrupted 4 times and completed on queue 5.
Process Synchronization
• The process needs to communicate with each to achieve the objective.
• For e.g.- create a file in MS word and when given print statement, it communicate with
printer driver program. OS act as interface between these communication.
• Generally, there are two types of process
• Independent
• Cooperating process
• Independent process are those which do not communicate with any other process. The
execution of one process does not affect the execution of other processes.
• In cooperating process are those which communicate with other processes for attaining
common goal. A process that can affect or be affected by other processes executing in the
system.
• Process Synchronization is the coordination of execution of multiple processes in a multi-
process system to ensure that they access shared resources in a controlled and
predictable manner.
• The main objective of process synchronization is to ensure that multiple processes access
shared resources without interfering with each other and to prevent the possibility of
inconsistent data due to concurrent access.
Need of Synchronization
Require between cooperating process.
To obtain expected result of execution.
Problems that can occur without
synchronization:
• Inconsistency
• Data Loss
• Deadlock
Where Synchronization required:
When two process wants to communicate
That is basically when u want to access share
common resources.
We store the common resource in critical
section.
It is segment of code where shared variables
is accessed
Race Condition:
• When more than one process is executing
the same code or accessing the same
memory or any shared variable in that
condition there is a possibility that the
output or the value of the shared variable is
wrong so for that all the processes doing the
race to say that my output is correct this
condition known as a race condition.
• Several processes access and process the
manipulations over the same data
concurrently, and then the outcome
depends on the particular order in which the
access takes place.
• A race condition is a situation that may
occur inside a critical section. This happens
when the result of multiple thread execution
in the critical section differs according to
the order in which the threads execute.
Requirements for Critical section Problem
• Mutual Exclusion
• Progress
• Bound Waiting
• In mutual exclusion, if a process is accessing critical
section , no other process is allowed to access the
critical section.
• In progress, If there is no process in the critical section
and any process is interested in accessing the critical
section, then the process is allowed to access the
critical section.
• In bound waiting , if a process is in critical section, and
other process is waiting to get into critical section. Then
the first process after completing doesn’t allow to
reenter in critical section again; so that other process is
bounded. (Alternative entering).
Solution using Lock
Solution using turn

Progress:
Not satisfied as P1 cannot proceed

Bounded Waiting :
Process can enter into the CS in strict
alternation
• Flag – to store the intention of process regarding entering the
critical section.
Petersons Solution • Turn – variable to give other one preference to enter into CS

Note : Work perfect


for only two process
Semaphore
• Semaphore is just a normal variable that
helps in achieving process
synchronization.
• They are used to enforce mutual
exclusion, avoid race conditions, and
implement synchronization between
processes.
• In order to access these semaphore
values, we use function
• Wait() or P() or Downgrade()
• Signal() or V() or Upgrade()
• Semaphores are of two types:
1.Binary Semaphore –
This is also known as a mutex
lock. It can have only two
values – 0 and 1. Its value is
initialized to 1. It is used to
implement the solution of
critical section problems with
multiple processes.
2.Counting Semaphore –
Its value can range over an
unrestricted domain. It is used to
control access to a resource that
has multiple instances.
Classical Problem of synchronization
• Bounded Buffer Problem/Producer Consumer Problem
• Reader Writer Problem
• Dining Philosopher Problem
• We have a buffer of fixed size. A producer can produce an item and can place in the
buffer. A consumer can pick items and can consume them.
• We need to ensure that when a producer is placing an item in the buffer, then at the same
time consumer should not consume any item.
• In this problem, buffer is the critical section.
Producer Consumer Problem
Reader Writer Problem

Solution

Writer Process
Case 1 : 1 writer 2 reader

Case 2 :
Dining Philosophers Problem
Solutions to DPP
Unit 3 : Deadlock
Operation on resources
• Request: to get control on access
• Use: After request granted, the process can
access the resource.
• Release: After accessing the resource , the
process has to release the resources.

• Deadlock:
• If two or more process waiting on event that
never occur, then these process are said to
be deadlock.
• E.g. – recruitment based on experience
• bat ball game between siblings
Necessary condition for Deadlock
• Deadlock can occur when all conditions are satisfied.
1. Mutual exclusion
2. Hold and wait
3. No preemption
4. Circular wait
Mutual exclusion
If one process is accessing or using any resources , no other
process is allowed to access that resource.
• Hold and wait:
One process should hold atleast one resource and wait for at least
one resource.
No pre-emption
No any resource should be pre-empted from any process.
Circular wait:
All deadlock process must wait for each other in circular manner.
Resource Allocation Graph(Directed)
• Generally two entities
Vertices Process
• Process
Resources
• Resources

Edge
• Request- from process to resource
• Allocation- from resource to process
Deadlock Tackling technique
• Deadlock prevention
• Deadlock avoidance
• Deadlock detection

You might also like