3. What is an Operating system?
An operating system (OS) is a software program that serves as an
interface between computer hardware and the user.
It manages the hardware resources of a computer system,
providing a set of services to software applications and enabling
communication between software and hardware components.
4. Cont’d
A fundamental piece of software which run on kernel mode(supervisor
mode).
A kernel is the core component of the OS, using inter-process
communication & system calls it act as a bridge b/w App’s and data
processing which is performed at H/w level.
It has complete access to all H/W & can execute any instruction the
machine is capable of executing
6. Role and Purpose of OS
It is a crucial software component that acts as an intermediary
between computer hardware and user applications.
Its primary role is to manage and coordinate the various resources
and functions of a computer system.
It provides a stable and efficient environment for users and
applications.
7. Function of OS
Memory Management
Processor Management
File management
Device Management
Security Management
User interfacing
Coordination of communication
Error detecting aids
8. Memory Management
Memory Management refers to management of Primary Memory or
Main Memory.
Allocating and de allocating memory to processes
Managing multiple processes within memory
keep track of which parts of memory are used by which processes.
Manage the sharing of memory between processes.
Determining which processes to load when memory becomes available.
9. Processor Management
✔ Keeps tracks of processor and status of process.
✔ Allocates the processor (CPU) to a process.
✔ De-allocates processor when a process is no longer required.
10. Device Management
✔ Keeps tracks of all devices.
✔ Decides which process gets the device when and for how much time.
✔ Allocates the device in the most efficient way.
✔ De-allocates devices.
11. File Management
✔ Keeps track of information, location, uses, status etc.
✔ Decides who gets the resources.
✔ Allocates the resources
✔ De-allocates the resources.
✔ responsible for archiving and backups.
12. Security Management
▪ By means of password and similar other techniques, it prevents
unauthorized access to programs and data.
13. Error detecting aids
▪ Production of dumps, traces, error messages, and other debugging
and error detecting aids.
14. Communication
▪ Processes may exchange information, on the same computer or
between computers over a network.
▪ Communications may be via shared memory or through message
passing (packets moved by the OS).
▪ Operating system also enables interposes communication
15. Generation of OS
1.First Generation:
• Operating systems in the 1950s had no distinction between system and
user functionalities, and they were closely tied to the hardware.
2.Second Generation:
• The 1960s saw the development of batch processing systems, where
multiple jobs were submitted and processed in batches, introducing more
sophisticated job control features.
3.Third Generation:
• In the 1970s, time-sharing systems emerged, allowing multiple users to
interact with the computer simultaneously, and the concept of multitasking
and multi-programming gained prominence.
16. Cont’d
4. Fourth Generation:
• The 1980s and 1990s witnessed the rise of graphical user interfaces
(GUIs) and the shift towards personal computing, with operating systems
like Windows, MacOS, and Linux becoming prominent.
5. Fifth Generation:
• The current era is characterized by distributed and networked computing,
with operating systems supporting advanced networking, virtualization,
and cloud computing technologies.
17. Types of OS
Based on number of user Operating System can be classified into
two
• Single user and
• multi user Operating system .
18. Single User OS
A single-user operating system (OS) is designed for one person to use at a
time.
It doesn't support multiple user sessions.
Example: Windows 95, Windows NT workstation, Windows 200
professionals
19. Single-user single Tasking OS
Allows a single user to execute one program at a particular time.
This operating system is designed especially for wireless phones and two-
way messaging.
Some functions such as
Printing a document, and
downloading images and videos are performed in one given frame.
20. Single-user multi Tasking OS
allows a single user to perform multiple tasks at once.
These operating systems are commonly found on personal laptops and
desktops
Examples :
Microsoft Windows,
Macintosh OS,
macOS,
Linux,
UNIX, MS-DOS, OS/2, Classic Mac OS.
22. Multi-User OS
It allows multiple users that are on different computers to access a single
system's OS resources simultaneously,
They are commonly found in servers and mainframes.
23. Cont’d
Some examples of multi-user operating systems include:
Linux: A popular multi-user operating system used in web servers
Windows Server: An example of a multi-user operating system used in
enterprise environments
UNIX: A multitasking, time-sharing system that allowed multiple users to
access the same resources at the same time
24. Characteristics of Multi-User OS
Distributed Resource Sharing:
• Several devices, like printers, fax machines, plotters, and hard drives,
can be shared in a multi-user operating system.
Multi-Tasking
Time sharing systems:
• These systems are multi-user systems in which CPU time is divided
among the users.
• The division is made on the basis of a schedule.
25. Advantage of Multi-User OS
can be used in the printing process to allow multiple users to access the
same printer, which a normal operating system may not do.
On a single computer system, several users can access the same copy of a
document.
If one computer fails in its own network system, the entire system does not
come to a halt.
Airlines use multi-user operating systems for some of their functions.
The ticket reservation system uses a multi-user operating system.
26. Disadvantage of Multi-User OS
Virus attacks occur simultaneously on all of them as the computers are
shared.
As a result, if one machine is affected, the others will be as well.
All computer information is shared publicly, and your personal information is
accessible to everyone on the network.
Multiple accounts on a single computer may not be suitable for all users.
Thus, it is better to have multiple PCs for each user.
27. Types of OS
Based on Functionality and design goals Operating System can be
classified
• Batch Operating System
• Time-Sharing Operating System
• Embedded Operating System
• Multiprogramming Operating System
• Network Operating System
• Distributed Operating System
• Multiprocessing Operating System
• Real-Time Operating System
28. Batch Operating System
there is no direct interaction between user and computer.
user needs to prepare jobs and save offline mode to punch card or
paper tape or magnetic tape.
After creating the jobs, hand it over to the computer operator; then the
operator sort or creates the similar types of batches like B2, B3, and
B4.
Now, the computer operator submits batches into the CPU to execute
the jobs one by one.
30. Time-sharing Operating System
allows us to connect many people located at different locations to
share and use a specific system at a single time.
The time-sharing operating system is the logical extension of the
multiprogramming through which users can run multiple tasks
concurrently.
It represents the CPU's time is shared between many user processes.
32. Embedded Operating System
It is the specific purpose operating system used in the computer
system's embedded hardware configuration.
These operating systems are designed to work on dedicated devices
like automated teller machines (ATMs), airplane systems, digital home
assistants, and the internet of things (IoT) devices.
34. Multiprogramming Operating System
A multiprogramming operating system refers to the concepts
wherein two or more processes or programs activate simultaneously to
execute the processes one after another by the same computer
system.
When a program is in run mode and uses CPU, another program or
file uses I/O resources at the same time or waiting for another system
resources to become available.
36. Network Operating System
It operates on a server using network devices like a switch, router, or
firewall to handle data, applications and other network resources.
It provides connectivity among the autonomous operating system,
called as a network operating system.
The network operating system is also useful to share data, files,
hardware devices and printer resources among multiple computers to
communicate with each other.
37. Cont’d
Types of network operating system
Peer-to-peer network operating system
• The type of network operating system allows users to share
files, resources between two or more computer machines
using a LAN.
Client-Server network operating system
• that allows the users to access resources, functions, and
applications through a common server or center hub of the
resources.
39. Distributed Operating System
provides an environment in which multiple independent CPU or
processor communicates with each other through physically separate
computational nodes.
Each node contains specific software that communicates with the
global aggregate operating system.
It is the extension of a network operating system that facilitates a high
degree of connectivity to communicate with other users over the
network.
41. Multiprocessing Operating System
refers to using two or more central processing units (CPU) in a single
computer system.
However, these multiprocessor systems or parallel operating systems
are used to increase the computer system's efficiency.
With the use of a multiprocessor system, they share computer bus,
clock, memory and input or output device for concurrent execution of
process or program and resource management in the CPU.
43. Real-Time Operating System
Used to provide services and data processing resources for
applications in which the time interval required to process & respond
to input/output should be so small without any delay real-time system.
For example, real-life situations governing an automatic car, traffic
signal, nuclear reactor or an aircraft require an immediate response to
complete tasks within a specified time delay.
real-time operating system must be fast and responsive for an
embedded system, weapon system, robots, scientific research &
experiments and various real-time objects.
44. Real-Time Operating System
Types of the real-time operating system
Hard Real-Time System:
• used with those required to complete critical tasks within the
defined time limit.
• If the response time is high, it is not accepted by the system
or may face serious issues like a system failure.
Soft Real-Time System
• It is a less restrictive system that can accept software and
hardware resources delays by the operating system.
45. Cont’d
• In a soft real-time system, a critical task prioritizes less
important tasks, and that priority retains active until completion
of the task.
• Also, a time limit is set for a specific job, which enables short
time delays for further tasks that are acceptable.
• For example, computer audio or video, virtual reality,
reservation system, projects like undersea, etc.
48. Process vs Program
Program:
It is sequence of instructions defined to perform some task.
A program is a piece of code which may be a single line or
millions of lines.
It is a passive entity.
Process:
It is a program in execution.
It is an instance of a program running on a computer
It is an active entity.
49. Cont’d
A processor performs the actions defined by a process.
A process is defined as an entity which represents the basic
unit of work to be implemented in the system.
50. Types of Process
Sequential Processes
• Execution progresses in a sequential fashion, i.e. one after the
other.
• At any point in time, at most one process is being executed.
Concurrent Processes
There are two types of concurrent processes:
True Concurrency (Multiprocessing)
Apparent Concurrency (Multiprogramming)
51. Cont’d
True Concurrency (Multiprocessing)
• Two or more processes are executed simultaneously in a
multiprocessor environment
• Supports real parallelism.
Apparent Concurrency (Multiprogramming)
• Two or more processes are executed in parallel in a
uniprocessor environment by switching from one process to
another.
• Supports pseudo parallelism, i.e. the fast switching among
processes gives illusion of parallelism.
52. Process Life Cycle
Process state : During its lifetime, a process passes through a
number of states.
I. New: A process that has just been created but has not yet been
admitted to the pool of executable processes by the operating
system
II. Ready : A process that is not currently executing but that is
ready to be executed as soon as the operating system
dispatches it.
III. Running: A process that is currently being executed
IV. Blocking (Waiting ): A process that is waiting for the completion
of some event, such as and I/O operation
53. Cont’d
V. Exit (Terminated): A process that has been released from the
pool of executable processes by the operating system, either
because it halted or because it aborted for some reason.
VI. Blocked/Suspend :The process is in secondary memory and is
waiting an event to occur.
VII. Ready/Suspend: The process is in secondary memory and is
available for execution as soon as it is loaded into main memory.
54. Process State Transitions
The main process state transitions are:
Null New
It occurs when a new process is created to execute a program.
New Ready
It occurs when the operating system is prepared to take on additional
process and a new process is admitted.
Ready Running
It occurs when the operating system chooses one of the processes in
the ready state for running.
The process is called dispatching and it is caused by the dispatcher
(scheduler).
55. Cont’d
Running Blocked
It occurs when a process requests something for which it must wait
Examples
- Request for an I/O operation and request for a file
- Request for another process to produce input
- Request for another process to produce a message
- Request for a shared section of a virtual memory
Blocked Ready
It occurs when the event for which a process has been waiting
occurs.
Wakeup (process name)
56. Cont’d
Running Ready
It occurs when a process is preempted by the operating system
Examples
- When time is expired
- When a blocked process with higher priority is moved to ready
state.
Running Exit
It occurs when a currently running process is terminated or
completes its task.
Halt (process name) or Abort (process name)
57. Cont’d
Ready Exit
Blocked Exit
It occurs due to two most common reasons
- When a parent process terminates a child process
- When a parent process is terminated
59. Threads and Multi-threading
Thread
• A thread is the smallest unit of execution within a process.
• It is a lightweight process
Process
• A process is an independent program in execution, and it has its own
memory space.
• It is a collection of one or more threads and associated system
resources.
Thread vs Process
60. Cont’d
A thread is a flow of execution through the process code with its own
program counter that keeps track of which instruction to execute next
system registers .
Each thread belongs to exactly one process and no thread can exist
outside a process.
Process switching needs interaction with operating system.
Thread switching does not need to interact with operating system.
61. Cont’d
Traditional operating systems are single-threaded systems.
Modern operating systems are multithreaded systems.
62. Multi-threading
Multithreading refers to concurrent execution of multiple threads (small
units of a process) by a single CPU.
It is a technique in which a process executing an application is divided
into threads that can run concurrently.
Each thread has independent context, state and stack.
63. Type of thread
Threads are implemented in following two ways −
I. User level threads
• threads that the OS is not aware of.
• They exist entirely within a process, and are scheduled to run
within that process's time slices.
• It is User managed threads.
II. Kernel level threads
• They are managed by the kernel.
• Operating System managed threads acting on kernel, an
operating system core.
65. Processor Scheduling
Processor Scheduling is the process of allocating a computer's
processing power to specific tasks.
All the resources of a computer system that are scheduled before use, the
CPU/processor is the far most important.
It involves assigning a specific percentage of the processor's running time
to individual tasks.
67. Cont’d
It can be implemented on uniprocessor systems (Uniprocessor
Scheduling), Multiprocessor systems (Multiprocessor Scheduling) .
The operating system makes three types of scheduling decisions with
respect to execution of processes:
Long-term Scheduling
Medium-term Scheduling
Short-term Scheduling
68. Cont’d
Long-term Scheduling
It is performed when a new process is created and
admitted
New Ready
Blocked/Suspend Ready/Suspend
Medium-term Scheduling
The decision to add to the number of processes that
are partially/fully in main memory
It determines when a program is brought partially or
fully into main memory so that it may be executed
69. Cont’d
Medium-term Scheduling
Ready/Suspend Ready
Blocked/Suspend Blocked
The decision of which ready process to execute next
It determines which ready process will get processor time
next
It is performed when a ready process is allocated the
processor (when it is dispatched)
Ready Running
Short-term Scheduling
70. Cont’d
Part of the operating system that makes scheduling decision is called
scheduler and
the algorithm it uses is called scheduling algorithm.
o Its functions are :
Process switch (Context Switch)
Mode Switch: Kernel User
Control branching: to the proper location in
the user program
71. Cont’d
Response Time (RT)
• The time from submission of request until the response begins to
be received.
• Where RT, response time, CFT, completion first time, AT, arrival
time
Scheduling Criteria
𝑅𝑇 = 𝐶𝐹𝑇 − 𝐴𝑇
72. Cont’d
Turn around Time (TAt)
• Turnaround time represents the total time taken to execute a
process, from the moment it arrives in the ready queue to the
moment it completes its execution.
• The time difference between the completion time and the arrival
time of a process / CPU service time(𝑆𝑇) plus waiting time (𝑊𝑡).
Scheduling Criteria
𝑇𝐴𝑡 = 𝐶𝑇 – 𝐴𝑇, or = 𝑆𝑇 + 𝑊𝑡
• Where ST is Burst/service time, WT is waiting time
73. Cont’d
Waiting Time (Wt)
• The time a process spends waiting in the ready queue before it
starts executing on the CPU.
• It is the difference between the total turnaround time and the
actual CPU burst time.
Scheduling Criteria
𝑊𝑡 𝑝𝑖 = 𝑊𝑡 𝑝𝑖−1 + 𝑆𝑇 𝑝𝑖−1 +𝐴𝑇 𝑃𝑖−1 - 𝐴𝑇 𝑃𝑖 , 𝑖𝑓 𝑡ℎ𝑒𝑖𝑟 𝑎𝑟𝑟𝑖𝑣𝑎𝑙 𝑡𝑖𝑚𝑒 𝑖𝑠 𝑑/𝑡
𝑊𝑡 𝑝𝑖 = 𝑗=1
𝐾
𝑆 𝑇 𝑃𝑗 , where 𝑘 = (𝑖 − 1), 𝑖𝑓 𝑡ℎ𝑒𝑖𝑟 𝑎𝑟𝑟𝑖𝑣𝑎𝑙 𝑡𝑖𝑚𝑒 𝑖𝑠 𝑒𝑞𝑢𝑎𝑙
For
only
non
preemptive
scheduling
𝑊𝑡 𝑝𝑖 = 𝑇𝐴𝑡 𝑝𝑖 − 𝑆𝑇 𝑝𝑖
74. Cont’d
Throughput (TP)
• Throughput is a measure of the system's efficiency in terms of the
number of processes it can complete within a given time frame.
• The number of processes completed per unit time.
Scheduling Criteria
𝑇𝑃=
𝑛
𝑖=1
𝑛 𝑆𝑇 𝑃𝑖
• Where P is process. 𝑖 = 1,2,3, … . 𝑛
75. Cont’d
Burst Time (ST)
• Burst time represents the amount of time a process needs to use
the CPU for its execution.
• It is a critical parameter in understanding the resource
requirements of a process
• The time required by a process for CPU execution.
Scheduling Criteria
76. Cont’d
Completion Time (CT)
• Completion time marks the end of a process's execution.
• The time at which a process completes its execution.
• It is the point in time when the process is considered finished.
Scheduling Criteria
𝑇𝐴𝑡
𝐶𝑇 = 𝐴𝑇 + W𝑡 + 𝑆𝑇
77. Cont’d
Arrival Time (AT)
• Arrival time signifies when a process becomes available for
execution.
• The time at which a process arrives in the ready queue.
• It is the point in time when the system starts considering the
process for execution.
Scheduling Criteria
78. Cont’d
• It determines which process, among ready processes, is selected
for execution
• It may be based on
Priority
Resource requirement
Execution behavior: time spent in system so far (waiting and
executing), time spent in execution so far, total service time required
by the process
Selection Functions
79. Short-term Scheduling Algorithms
1. First-Come-First-Served Scheduling (FCFSS)
2. Shortest Job First Scheduling (SJFS)
3. Shortest Remaining Time Scheduling (SRTS)
4. Round Robin Scheduling (RRS)
5. Priority Scheduling (PS)
Process scheduling algorithms
80. Cont’d
Basic Terminology
• Completion Time
• Turn Around Time Average Turn Around Time
• Waiting Time Average Waiting Time
• Response Time Average Response time
• Throughput
81. Cont’d
First-Come-First-Served Scheduling (FCFSS)
Jobs are executed on first come, first serve basis.
Its selection function is waiting time .
Its implementation is based on FIFO queue.
Poor in performance as average wait time is high.
Example: :- Let’s consider the following three processes are
processed under FCFSS in arrive at time 0.
82. Example
Let’s consider the following three processes are processed under FCFSS in arrive at time 0.
Process P1 P2 P3
CPU Burst/Service Time (in ms) 24 3 3
Waiting Time 0 24
27
Turn around Time 24 27 30
𝐴𝑣𝑤𝑡 =
𝑖=1
𝑛
𝑤𝑡 𝑃𝑖
𝑛
𝐴𝑣𝑇𝐴𝑡 =
𝑖=1
𝑛
𝑇𝐴𝑡 𝑃𝑖
𝑛
=
0 + 24 + 27
3
=
24 + 27 + 30
3
= 17
= 27
Turn around Time 24 27 30
𝑇𝑃 =
𝑛
𝑖=1
𝑛
𝑆𝑇 𝑃𝑖
=
3
24 + 3 + 3 = 0.1
83. Example
Let’s consider the following three processes are processed under FCFSS in arrive at time 0,
1, 2, 3 respectively.
Process P1 P2 P3 P4
Arrival Time (𝐴𝑇) 0 1 2 3
CPU Burst/Service Time (in ms ) 1 100 1 100
Waiting Time (𝑤𝑡) 0 0 99 99
Turn around Time 1 100 100
199
𝑇𝐴𝑡 𝑝1 = 𝑤𝑡 𝑃1 + 𝑆𝑇 𝑃1 = 0 + 1 + 0 − 0 = 1
𝑇𝐴𝑡 𝑝2 = 𝑤𝑡 𝑃2 + 𝑆𝑇 𝑃2 = 1 + 100 + 0 − 1 = 100
84. Cont’d
Let’s consider the following three processes are processed under FCFSS in arrive at time 0,
1, 2, 3 respectively.
Process P1 P2 P3 P4
Arrival Time (𝐴𝑇) 0 1 2 3
CPU Burst/Service Time (in ms ) 1 100 1 100
Waiting Time (𝑤𝑡) 0 0 99 99
Turn around Time 1 100 100
199
𝑇𝐴𝑡 𝑝3 = 𝑤𝑡 𝑃3 + 𝑆𝑇 𝑃3 = 2 + 1 + 99 − 2 = 100
𝑇𝐴𝑡 𝑝4 = 𝑤𝑡 𝑃4 + 𝑆𝑇 𝑃4 = 3 + 100 + 99 − 3 = 199
85. Cont’d
Let’s consider the following three processes are processed under FCFSS in arrive at time 0,
1, 2, 3 respectively.
Process P1 P2 P3 P4
Arrival Time (𝐴𝑇) 0 1 2 3
CPU Burst/Service Time (in ms ) 1 100 1 100
Waiting Time (𝑤𝑡) 0 0 99 99
Turn around Time 1 100 100
199
𝐴𝑣𝑤𝑡 =
𝑖=1
𝑛
𝑤𝑡 𝑃𝑖
𝑛
𝐴𝑣𝑇𝐴𝑡 =
𝑖=1
𝑛
𝑇𝐴𝑡 𝑃𝑖
𝑛
𝑇𝑃 =
𝑛
𝑖=1
𝑛
𝑆𝑇 𝑃𝑖
=
0 + 0 + 99 + 99
4
= 49.5
=
1 + 100 + 100 + 199
4
= 100
=
4
1 + 100 + 1 + 100
= 0.0198
86. Cont’d
Shortest-Job-First Scheduling (SJFS)
this is known as shortest job first service .
Best approach to minimize waiting time .
Its selection function is execution time.
Process with the shortest expected processing time (CPU burst) is
selected next.
Example: :- SJFS let’s consider three process are processed under
SJFS in arrive at time is 0
87. Example
Let’s consider the following three processes are processed under SJFS in arrive at time 0.
Process P1 P2 P3
CPU Burst/Service Time (in ms) 24 3 3
Turn around Time 30 3 6
Turn around Time 24 27 30
Waiting Time 6 0 3
𝑤𝑡 𝑃1 = 𝑇𝐴𝑡 𝑃1 − 𝑆𝑇 𝑃1 = 30 – 24 = 6
𝑤𝑡 𝑃2 = 𝑇𝐴𝑡 𝑃2 − 𝑆𝑇 𝑃2 = 3 – 3 = 0
𝑤𝑡 𝑃3 = 𝑇𝐴𝑡 𝑃3 − 𝑆𝑇 𝑃3 = 6 – 3 = 3
𝐴𝑣𝑇𝐴𝑡 =
𝑖=1
𝑛
𝑇𝐴𝑡 𝑃𝑖
𝑛 =
30 + 3 + 6
3
= 13
CT 𝑃1 = 𝑇𝐴𝑡 𝑃1 + 𝐴𝑇 𝑃1 = 30+0=30
𝐶𝑇 𝑃2 = 𝑇𝐴𝑡 𝑃2 + 𝐴𝑇 𝑃2 = 3 + 0 = 3
CT 𝑃3 = 𝑇𝐴𝑡 𝑃3 + 𝐴𝑇 𝑃3 = 6 + 0 = 6
P2 P3 P1
0 3 6
30
Completion Time
𝐴𝑣𝑤𝑡 =
𝑖=1
𝑛
𝑤𝑡 𝑃𝑖
𝑛
=
6 + 0 + 3
3
= 3
88. Example
let’s consider the following five processes are processed under SJFS in arrive at time 0, 2, 4,
6, 8 respectively.
Process P1 P2 P3 P4
P5
Arrival Time (𝐴𝑇) 0 2 4 6
8
CPU Burst/Service Time (in ms ) 3 6 4 5
2
Turn around Time (𝑇𝐴𝑡) 3 7 11 14
3
Waiting Time 0 1 7 9
1
=
3 + 7 + 11 + 14 + 3
5
= 7.6
=
0 + 1 + 7 + 9 + 1
5
= 3.6
=
5
3 + 6 + 4 + 5 + 2
= 0.25
𝐴𝑣𝑇𝐴𝑡 =
𝑖=1
𝑛
𝑇𝐴𝑡 𝑃𝑖
𝑛
𝐴𝑣𝑤𝑡 =
𝑖=1
𝑛
𝑤𝑡 𝑃𝑖
𝑛
𝑇𝑃 =
𝑛
𝑖=1
𝑛
𝑆𝑇 𝑃𝑖
90. Cont’d
The process that has the shortest expected remaining process
time.
If a new process arrives with a shorter next CPU burst than what
is left of the currently executing process, the new process gets the
CPU.
Its selection function is remaining execution time.
The processor is allocated to the job closest to completion but it
can be preempted by a newer ready job with shorter time to
completion.
Shortest-Remaining-Time Scheduling (SRTS)
91. Example
Example:- Find completion time, average turn around and average waiting time?
Also find response time for each process?
Process P1 P2 P3
P4
Arrival Time (𝐴𝑇) 0 1 2
4
CPU Burst/Service Time (in ms ) 5 3 4
1
92. Cont’d
Solution: compute completion time at 𝟏 𝒎𝒔 interval and compare burst time of each
process.
If their burst time is equal, check their arrival time.
0 − 1 𝑚𝑠 𝑃1 𝑅𝑒𝑚𝑎𝑖𝑛𝑖𝑛𝑔 𝑆𝑇 = 4
Completion Time
Process 𝑃1 𝑃2 𝑃3 𝑃4
𝐴𝑇 0 1 2
4
ST 4 3 4
1
Always start the process first arrived
in range (P1)
Select P1
1 − 2 𝑚𝑠 𝑃2 𝑅𝑒𝑚𝑎𝑖𝑛𝑖𝑛𝑔 𝑆𝑇 = 2
Process 𝑃1 𝑃2 𝑃3 𝑃4
𝐴𝑇 0 1 2
4
ST 4 2 4
In range (𝑃1, 𝑃2)
Select P2
93. Cont’d
Always start with the process first arrived, if two process have equal arrival time check
their burst time
2 − 3 𝑚𝑠 𝑃2 𝑅𝑒𝑚𝑎𝑖𝑛𝑖𝑛𝑔 𝑆𝑇 = 1
Completion Time
Process 𝑃1 𝑃2 𝑃3 𝑃4
𝐴𝑇 0 1 2
4
ST 4 1 4
1
In range (𝑃1, 𝑃2, 𝑃3)
Select P2, because ST(P2) is less than from
all in range
3 − 4 𝑚𝑠 𝑃2 𝑅𝑒𝑚𝑎𝑖𝑛𝑖𝑛𝑔 𝑆𝑇 = 0
Process 𝑃1 𝑃2 𝑃3 𝑃4
𝐴𝑇 0 1 2
4
ST 4 0 4
In range (𝑃1, 𝑃2, 𝑃3)
Select P2, because ST(P2) is less than from
all in range
P2 is finished.
94. Cont’d
Since P2 finished, remove from range list after 4 𝑚𝑠.
4 − 5 𝑚𝑠 𝑃4 𝑅𝑒𝑚𝑎𝑖𝑛𝑖𝑛𝑔 𝑆𝑇 = 0
Completion Time
Process 𝑃1 𝑃2 𝑃3 𝑃4
𝐴𝑇 0 1 2 4
ST 4 0 4 0
In range (𝑃1, 𝑃3, 𝑃4)
Select P4, because P4 ST <
(P1 ST & P3 ST )
5 − 6 𝑚𝑠 𝑃1 𝑅𝑒𝑚𝑎𝑖𝑛𝑖𝑛𝑔 𝑆𝑇 = 3
Process 𝑃1 𝑃2 𝑃3 𝑃4
𝐴𝑇 0 1 2 4
ST 3 0 4 0
In range (𝑃1, 𝑃3), P1 ST = P3(ST)
Select P1, because P1 (AT) < P3(AT)
P4 is finished.
95. Cont’d
Since P4 finished, remove from range list 5 𝑚𝑠.
6 − 7 𝑚𝑠 𝑃1 𝑅𝑒𝑚𝑎𝑖𝑛𝑖𝑛𝑔 𝑆𝑇 = 2
Completion Time
Process 𝑃1 𝑃2 𝑃3 𝑃4
𝐴𝑇 0 1 2 4
ST 2 0 4 0
In range (𝑃1, 𝑃3), P1 ST < P3(ST)
Select P1
7 − 8 𝑚𝑠 𝑃1 𝑅𝑒𝑚𝑎𝑖𝑛𝑖𝑛𝑔 𝑆𝑇 = 1
Process 𝑃1 𝑃2 𝑃3 𝑃4
𝐴𝑇 0 1 2 4
ST 1 0 4 0
In range (𝑃1, 𝑃3), P1 ST < P3(ST)
96. Cont’d
Since P1 finished, remove from range list after 9 𝑚𝑠.
8 − 9 𝑚𝑠 𝑃1 𝑅𝑒𝑚𝑎𝑖𝑛𝑖𝑛𝑔 𝑆𝑇 = 0
Completion Time
Process 𝑃1 𝑃2 𝑃3 𝑃4
𝐴𝑇 0 1 2 4
ST 0 0 4
0
In range (𝑃1, 𝑃3),
Select P1, becauseP1 ST < P3(ST))
9 − 10 𝑚𝑠 𝑃3 𝑅𝑒𝑚𝑎𝑖𝑛𝑖𝑛𝑔 𝑆𝑇 = 3
Process 𝑃1 𝑃2 𝑃3 𝑃4
𝐴𝑇 0 0 2 4
ST 0 0 3
0
Select P3, because only P3 left
P1 is finished.
97. Cont’d
Repeat the steps until ST(P3) == 0
10 − 11 𝑚𝑠 𝑃3 𝑅𝑒𝑚𝑎𝑖𝑛𝑖𝑛𝑔 𝑆𝑇 = 2
Completion Time
Process 𝑃1 𝑃2 𝑃3 𝑃4
𝐴𝑇 0 1 2 4
ST 0 0 2
0
Select P3, because only P3 left
11 − 12 𝑚𝑠 𝑃3 𝑅𝑒𝑚𝑎𝑖𝑛𝑖𝑛𝑔 𝑆𝑇 = 1
Process 𝑃1 𝑃2 𝑃3 𝑃4
𝐴𝑇 0 0 2 4
ST 0 0 1
0
98. Cont’d
Repeat the steps until ST(P3) == 0
12 − 13 𝑚𝑠 𝑃3 𝑅𝑒𝑚𝑎𝑖𝑛𝑖𝑛𝑔 𝑆𝑇 = 0
Completion Time
Process 𝑃1 𝑃2 𝑃3 𝑃4
𝐴𝑇 0 1 2 4
ST 0 0 0
0
Now, All process finished.
P3 is finished.
99. Cont’d
Completion Time Gant chart
Process P1 P2 P3
P4
Arrival Time (𝐴𝑇) 0 1 2
4
CPU Burst/Service Time (in ms ) 5 3 4
1
Completion Time (𝐶𝑇) 9 4 13
5
Turn around time (𝑇𝐴𝑡) 9 3 11
1
Waiting Time (𝑤𝑡 in ms ) 4 0 7
0
Response Time(𝑅𝑡 in ms ) 0 0 7
0
P1 P2 P4 P1 P3
0 1 4 5 9 13
101. Assignment(5%)
Find completion time, average turn around and average waiting time?
Also find response time for each process? Show all the necessary steps.
Process P1 P2 P3 P4 P5
P6
Arrival Time (𝐴𝑇) 0 1 2 3 4
5
CPU Burst/Service Time (in ms ) 9 8 3 5 2
1
102. Cont’d
Its selection function is based on quantum .
The ready queue is treated as a circular queue.
Each process is provided a fix time to execute , it is called a
Quantum.
• Once a process is executed for a given time period.
• it is preempted and other process executes for a given time
period.
• Context switching is used to save states of preempted
processes.
Round-Robin Scheduling (RRS)
103. Example
Let's consider four process are processed under Round Robin Scheduling with arrival
time is 0 and Quantum =5.
Process P1 P2 P3
P4
Arrival Time (𝐴𝑇) 0 0 0
0
CPU Burst/Service Time (in ms ) 21 3 6
2
108. Cont’d
Completion Time
31 − 32 𝑚𝑠 𝑃1 𝑅𝑒𝑚𝑎𝑖𝑛𝑖𝑛𝑔 𝑆𝑇 = 0
Process 𝑃1 𝑃2 𝑃3 𝑃4
𝐴𝑇 0 0 0
0
ST 0 0 0
0
P1 finished.
109. Cont’d
Completion Time Gant chart
Process P1 P2 P3
P4
Arrival Time (𝐴𝑇) 0 0 0
0
CPU Burst/Service Time (in ms ) 21 3 6
2
Completion Time (𝐶𝑇) 32 8 21
15
Turn around time (𝑇𝐴𝑡) 32 8 21
15
Waiting Time (𝑤𝑡 in ms ) 11 5 15
13
Response Time(𝑅𝑡 in ms ) 0 5 8
P1 P2 P3 P4 P1 P3 P1 P1 P1
0 5 8 13 15 20 21 26 31 32
111. Assignment(5%)
Find completion time, average turn around and average waiting time?
Also find response time for each process? Show all the necessary steps. Quantum=2
Process P1 P2 P3
P4
Arrival Time (𝐴𝑇) 5 1 3
9
CPU Burst/Service Time (in ms ) 21 3 6
2
112. Inter-Process Communication(IPC)
It is a mechanism which allows processes to communicate each
other and synchronize their actions.
Exchange of data and control information .
Shared memory and Message passing .
There are several methods of IPC, and the choice of method depends
on the requirements of the processes involved.
Inter-Process communication
114. Cont’d
The fundamental design issue in the management of multiple
processes is concurrency: simultaneous execution of multiple
processes.
Concurrency arises in three different contexts
• Multiple applications: concurrently running applications
• Structured applications: an application structured as a set of
concurrent processes (threads)
• OS structure: OS implemented as a set of processes
Concurrency Problems
115. Cont’d
Concurrency is the interleaving of process in time to give the
appearance of simultaneous execution.
There are some serious problems associated with the interaction of
concurrently running processes:
I. Deadlock
II. Starvation
III. Mutual Exclusion
116. Cont’d
It occurs when two or more processes require resources that can't be
shared simultaneously.
This can occur when each process is holding a resource that the other
process needs.
Deadlocks can be a serious problem in multi-tasking operating
systems, as they can prevent processes from completing their tasks.
I).Deadlocks
117. Cont’d
Deadlock can arise if the following four condition is holds
simultaneously.
• Mutual exclusion:
One or more than one resource are non-sharable(Only one process
can use at a time).
• Hold and Wait:
A process is holding at least one resource and waiting for resources.
• No preemption:
A resource cannot be taken from a process unless the process
releases the resource
119. Cont’d
• No Preemption
We can take a resource from one process and give it to other.
This will resolve the deadlock situation, but sometimes it does
causes problems.
• Rollback:
This might include rolling back transactions or releasing resources
that a process holds so that other processes can proceed.
Methods of handling deadlocks
120. Cont’d
• Kill one or more process
To prevent deadlocks, one common strategy is to kill or terminate
processes that are identified as potential sources of deadlock.
121. Example
Suppose a machine has 64MB of memory. The following sequence
of events occurs.
1. Process A starts, using 30MB of memory.
2. Process B starts, also using 30MB of memory.
30MB 30MB 4MB
A B free
64MB
122. Cont’d
3. Process A requests an additional 8MB of memory. The kernel blocks
process A’s thread, since there is only 4MB of available memory.
4. Process B requests an additional 5MB of memory. The kernel blocks
process B’s thread, since there is not enough memory available.
These two processes are deadlocked - neither process can make
progress.
Waiting will not resolve the deadlock.
The processes are permanently stuck.
123. Reading Assignment
I. Starvation
II. Mutual Exclusion
III. Implementing Mutual Exclusion with Busy Waiting
IV. Implementing Mutual Exclusion without Busy Waiting
125. Memory
Computer memory is a storage space that stores data and instructions for
processing.
It's a vital link between the computer's software and its CPU.
Computer memory is made up of many small parts called cells.
Each cell stores one or more transistors, which contain binary data.
The cells have unique addresses, ranging from zero to the memory size
minus one.
Before a program can be run the program is loaded from the storage
medium into memory.
127. Cont’d
It allows the CPU to direct interact with the program.
Memory is a need of every computer
128. Types of Memory
❏ROM (Read Only Memory)
❏RAM (Random Access memory)
❏Cache memory
❏Flash Memory
129. Cont’d
ROM (Read Only Memory)
Stores data without electrical current.
It is sometimes called non-volatile memory as it is not erased when the
system is switched off.
130. Cont’d
RAM (Random Access Memory)
Any byte of memory can be accessed without touching the preceding
bytes.
RAM is the most common type of memory found in computers and other
devices, such as printers.
131. Cont’d
Cache Memory
It stores frequently used computer programs, applications, and data.
Provides high-speed data access to a processor.
It acts as a buffer between the main memory (RAM) and the central
processing unit (CPU).
132. Cont’d
Flash Memory
Non volatile memory can be erased electronically and rewritten similar to
EEPROM.
Introduced by Toshiba in 1984.
Most computers use it to hold up their startup instructions.
Also used in many mobiles , smart phones , digital cameras and PDA.
133. Swapping
Swapping is process of moving data between the random access memory
(RAM) and the storage (usually a hard disk(HDD) or SSD) to free up space
in the RAM for other processes.
When the available RAM is insufficient to hold all the data and applications
that are actively in use, the operating system may use swapping to manage
memory resources more effectively.
134. Cont’d
Swap Out: When the operating system determines that certain data or
program code in RAM is not actively being used, it can transfer (or "page
out") that data from RAM to a designated space on the storage device,
creating what is known as a "swap file" or "page file.“
Swap In: When the data that was swapped out is needed again, the
operating system can bring it back into RAM from the swap file. This is
known as "paging in."
General swapping process
136. Cont’d
It allows programs to run as if they have more memory than the physical
RAM by temporarily transferring data to and from a storage device.
Virtual memory provides benefits in terms of costs, physical space,
multitasking capabilities, and data security.
Each program has its own address space, which is broken into chunks
called pages
• Each page is a contiguous range of addresses
• These pages are mapped onto physical memory to run
Virtual Memory
137. Paging and Segmentation
Paging involves breaking up the physical memory into fixed-size blocks
called pages.
Simultaneously, the logical address space is divided into blocks of the same
size, known as page frames.
The operating system keeps a mapping table, known as the page table, to
map logical pages to physical page frames.
Page Size: The size of each page is a critical parameter in paging. Common
page sizes are 4 KB, 2 MB, or 4 MB.
Paging
138. Cont’d
Page Table: This table is used to translate logical addresses to physical
addresses.
It contains entries for each page, indicating the corresponding frame in
physical memory.
A computers that generates 16 bit addresses from o to 64KB these are
called the virtual address
139. Example
The computer has only 32KB of physical memory
64KB programs can be written they cannot be loaded into memory in their
entirety and run
A copy of program core image up to 64KB must be present on disk so that
pieces can be brought in as needed
Virtual address space is divided into fixed size units called pages
Corresponding units in the physical memory called page frames
Pages and page frames are generally same size
With 64KB of virtual pages and 8 page frames
140. Cont’d
0k -4k means that virtual or physical address in that are 0 to 4095
4k – 8k means 4096 - 8191
When the program tries to access address ZERO using the instruction MOV
REG 0
Virtual address 0 is sent to MMU
142. Cont’d
• MOVE REG 0
Thus MMU has mapped all virtual address between zero and 4095 to physical address
8192 to 12287
MOVE REG 8192 is effectively moved to 24576
143. Cont’d
Segmentation is another way of dividing the addressable memory.
It is another scheme of memory management and it generally supports the
user view of memory.
The Logical address space is basically the collection of segments.
Each segment has a name and a length.
Segmentation
144. Cont’d
Basically, a process is divided into segments. Like paging, segmentation
divides or segments the memory.
A logical address is two dimensional with segment number and offset in
segment.
Each process has a segment table that specifies where the segments are
allocated.