Professional Documents
Culture Documents
Code: CSPC-303
By
Dr K P Sharma
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
CSPC-214
CO 1 L H L M
CO 2 M L L
CO 3 M H M
CO 4 M M H M 2
TOPICS TO BE COVERED
Operating systems objectives, services and functions: Characteristics of Modern Operating
Systems, Characteristics of Batch and multiprogramming operating systems. Comparisons
between real time systems and time-sharing systems, Operating system services and kernel
features.
I/O management, I/O devices: Introduction to I/O management, I/O devices, Concepts of
threading, Organization of I/O functions, polling, various modes of data transfer,
Hardware/Software interface, I/O buffering.
Processes and Process scheduling policies: Introduction to processes management, operating
system views of processes, various process transition states, Introduction to Processor
scheduling, Introduction to various types of schedulers, Performance criteria in scheduling
algorithms, Concept of FCFS scheduling algorithm, Concept of priority scheduling algorithm
like SJF, Concept of non-preemptive and preemptive algorithms, Concept of round-robin
scheduling algorithm, , Concept of multi-level queues, feedback queues.
Concurrency control schemes: Various approaches to concurrency control schemes, Concept
of prouder/consumer problem, Mutual Exclusion, Concept of mutual exclusion first and second
algorithm, Concept of mutual exclusion third algorithm including introduction and
characteristics of semaphores, Introduction to Mutual exclusion with semaphores, Introduction
to Interprocess Communication and Synchronization, Critical regions and Conditional critical
regions in a Semaphore. Introduction to monitors, various modes of monitors.
3
Dead Locks: Concept of Deadlocks, issues related to its prevention, avoidance and
detection / recovery, Concept of deadlock prevention and its avoidance, Concept of
deadlock detection and recovery.
Memory Management: Need of Memory management and its requirements, paging,
segmentation, concept of fragmentation. Characteristics of contiguous & non-contiguous
allocation techniques, Detail study of fragmentation, Virtual memory management,
introduction to page-replacement, Need of various page-replacement policies, Concept of FIFO
and optimal page-replacement algorithms, Concept of LRU approximation and its page-
replacement algorithm, Concept of allocation algorithms.
File management System: Need of file management, its requirements, User’s and operating
system’s view of file system, Concept of file directories and file sharing, secondary memory
management.
TEXT BOOKS, AND/OR REFERENCE MATERIAL
Peterson and Silberschatz, “Operating System Concepts”, Addison-Wesley 6th Edition 2006.
Milenkoviac, “Operating Systems Concepts and Design”, Tata McGraw-Hill 2005.
Andrews S. Tanenbaum, “Modern Operating Systems”, Pearson Education, 3nd edition 2016.
W Stallings, “ Opertating Systems” Pearson, 6th Edition 2012
Dhamdhere, D M, “Introduction to Systems Software”, Tata Mc-Graw Hill 2015
N Chauhan, “Principles of Operating Systems” 1st ed. 2018 4
What is an Operating System?
User programs
programming environment
Operating system interface
Operating system
Hardware interface
Hardware
What does the OS achieve?
Make it easy to write programs
• Add more powerful instructions to the hardware instruction set.
• What kind of instructions are added?
– Common functions used by many different applications.
– E.g. write (fileno, buf, len);
• Resource virtualization
• E.g. the illusion of Infinite memory.
Make it easy to run programs
• How does a program run on the raw machine?
• The program is in memory, starting from program counter (pc),
run one instruction, goto the next instruction, run until the
halt instruction.
• How do you run a program?
• g++ helloworld.cpp and then a.out.
The OS must fill the gap between how you run a program
and how the hardware runs a program. The OS must be able
to:
• Take the user command (g++, a.out, etc) – shell
• Find the executable file (g++ or a.out) – File system
• Load the executable into memory – memory management
• Set the registers properly (e.g. pc = starting address of the
executable)
• When there are multiple programs running, the OS must make each
program feel like it solely owns the whole machine (CPU, memory,
registers) – virtual machine for each process
• Manage processes.
OS functionality: Implements the OS interface +
resource management
What does an OS achieve?
It hides the complexity and limitations of hardware (hardware
interface) and creates a simpler, more powerful abstraction (OS
interface).
Hardware reality vs. OS abstraction
Reality Abstraction
A single CPU Multiple CPUs
Limited RAM capacity Infinite capacity
Mechanical disk Memory speed access
Insecure and Reliable and secure
unreliable networks
Many physical A single machine
machines
Operating System Services
An Operating System provides services to both the users and to the
programs.
It provides programs an environment to execute.
It provides users the services to execute the programs in a convenient manner.
Some common services of OS
• Program execution
• I/O operations
• File System manipulation
• Communication
• Error Detection
• Resource Allocation
• Protection
17
Program Execution
Operating systems handle many kinds of activities from user
programs to system programs like printer spooler, name servers,
file server, etc. Each of these activities is encapsulated as a process.
Following are the major activities of an OS with respect to program
management −
• Loads a program into memory.
• Executes the program.
• Handles program's execution.
• Provides a mechanism for process synchronization.
• Provides a mechanism for process communication.
• Provides a mechanism for deadlock handling.
18
I/O Operation
An I/O subsystem comprises of I/O devices and their
corresponding driver software. Drivers hide the peculiarities of
specific hardware devices from the users.
An Operating System manages the communication between user
and device drivers.
• I/O operation means read or write operation with any file or
any specific I/O device.
• Operating system provides the access to the required I/O
device when required.
19
File system manipulation
A file represents a collection of related information.
Computers can store files on the disk (secondary storage), for long-term storage
purpose. Examples of storage media include magnetic tape, magnetic disk and
optical disk drives like CD, DVD.
Each of these media has its own properties like speed, capacity, data transfer rate
and data access methods.
For ease of use OS provides an easy manageable view of file system in the form
of directories and file icons.
Following are the major activities of an operating system with respect to file
management −
• Program needs to read a file or write a file.
• The operating system gives the permission to the program for operation on file.
• Permission varies from read-only, read-write, denied and so on.
• Operating System provides an interface to the user to create/delete files.
• Operating System provides an interface to the user to create/delete directories.
• Operating System provides an interface to create the backup of file system.
20
Communication
In case of distributed systems which are a collection of processors that do not
share memory, peripheral devices, or a clock, the operating system manages
communications between all the processes.
Multiple processes communicate with one another through communication lines
in the network.
Following are the major activities of an operating system with respect to
communication −
• Two processes often require data to be transferred between them
• Both the processes can be on one computer or on different computers, but
are connected through a computer network.
• Communication may be implemented by two methods, either by Shared
Memory or by Message Passing.
21
Error handling
Errors can occur anytime and anywhere. An error may occur in
CPU, in I/O devices or in the memory hardware. Following are the
major activities of an operating system with respect to error
handling −
• The OS constantly checks for possible errors.
• The OS takes an appropriate action to ensure correct and
consistent computing.
22
Resource Management
In case of multi-user or multi-tasking environment, resources such
as main memory, CPU cycles and files storage are to be allocated
to each user or job. Following are the major activities of an
operating system with respect to resource management −
• The OS manages all kinds of resources using schedulers.
• CPU scheduling algorithms are used for better utilization of
CPU.
• Deadlock prevention and avoidance
• Error handling due to sharing of common recourses by multiple
processes
23
Protection
Example: Protection
• Applications should not crash one another
• Address space: all memory addresses that an application can touch.
• Address space for one process is separated from address space for another
process and from the OS.
• Applications should not crash the OS
• Dual-mode operations
– Kernel mode: some instructions can only be executed by the OS (must be
executed with a kernel mode).
– User mode: an application can only access its own address space
– Examples of kernel mode instructions?
Kernel mode or Privileged Instructions Non-Kernel or non Privileged Instructions
• I/O instructions and Halt instructions • Reading the status of Processor
• Turn off all Interrupts • Reading the System Time
• Set the Timer • Generate any Trap Instruction
• Context Switching
• Sending the final printout of Printer
• Clear the Memory or Remove a process from
the Memory
• Modify entries in Device-status table
Resources managed by OS
Processor (CPU)
• Runs program instructions
Main Memory
• Storage for running programs and current data
Secondary Storage
• Long-term program & data storage (hard disk, CD, etc)
Input Devices
• Communication from the user to the computer(e.g.
keyboard, mouse)
Output Devices
• Communication from the computer to the user (e.g.
monitor, printer, speakers)
Computer Components: Top Level View
The CPU
TheCPU is a silicon chip that contains millions of tiny electrical
components.
Coordinates
Control Unit
processing steps
Small, fast
Registers storage areas
for
instructions
and data
Registers
Registers are small, fast memory within the CPU
Different registers hold different things like instructions and addresses of
instructions, data (operands) and results of operations
These are of two types
Megabyte (MB) = 1024 x 1024 bytes or one million bytes (220 bytes)
Gigabyte (GB) = 1024 x 1024 x 1024 bytes or 1 trillion bytes (230 bytes)
Terabyte (TB) = 1024 x 1024 x 1024 x 1024 bytes one quadrillion bytes (240 bytes)
MEMORY CLASSIFICATION
Registers
2ns
Cache (I, II, III)
Volatile SRAM
DRAM
Primary SDRAM
(Semiconductor – RAM EDRAM
chip). Main Memory
EDO
FLASH RAM
Memory Types &
Storage Devices PROM
Non-volatile EPROM
ROM EEPROM
Tape
Magnetic memory HD, Zip Disk
Secondary FDD
(Devices)
Optical
CD-ROM, CD-R, CD-RW
Memory DVD-ROM, DVD-R 5ms
DVD- RW
PRIMARY MEMORY: RAM AND ROM
RAM (Random Access Memory) is volatile (temporary). Programs
and data can be written to and erased from RAM as needed. This
means that RAM does not retain its bit configuration when the
power is turned off, but ROM does.
• SRAM: static RAM
• No need to be refreshed, made up of transistors to construct flip flops,
costly and fast, used as cache memory
• DRAM: dynamic RAM
• Need to be refreshed periodically, Made up of capacitors and transistors
• Main memory
The organization
of a magnetic disk
CPU and Memory
CPU can interact with main memory in two ways:
• It can write a byte/word to a given memory location.
• The previous bits that were in that location are
destroyed
• The new bits are saved for future use.
• It can read a byte/word from a given memory location.
• The CPU copies the bits stored at that location and
stores them in a CPU register
• The contents of the memory location are NOT
changed.
Main Memory Characteristics
44
Program Instructions
53
Example of Program Execution
Interrupt Cycle
Added to instruction cycle
Processor checks for interrupt
• Indicated by an interrupt signal
If no interrupt, fetch next instruction
If interrupt pending:
• Suspend execution of current program
• Save context
• Set PC to start address of interrupt handler routine
• Process interrupt
• Restore context and continue interrupted program
Transfer of Control via Interrupts
Instruction Cycle with Interrupts
Access to Instructions
Applications
e.g. Word, Netscape, etc
Operating System –
- the user interface
Software that
controls the
hardware devices
How Programs Are Run
Each user gets time of CPU as they use single system. These
systems are also known as Multitasking Systems.
The task can be from single user or from different users also.
The time that each task gets to execute is called quantum. After this
time interval is over OS switches over to next task.
Advantages of Time-Sharing OS:
• Each task gets an equal opportunity
• Less chances of duplication of software
• CPU idle time can be reduced
Interrupts are signals sent to the CPU by external devices, normally I/O
devices. They tell the CPU to stop its current activities and execute the
appropriate part of the operating system.
Types of Interrupts
•Hardware
•Software
•TRAP
Operating-System Operations
• Operating system is an Interrupt Driven System
77
Multiprogramming and Multitasking
One of the most important aspects of operating systems is the ability
to run multiple programs, as a single program cannot, in general,
keep either the CPU or the I/O devices busy at all times.
78
Memory Layout for Multiprogrammed System
Modes of Operation
A mechanism that allows the OS to protect itself and other
system components
Two modes:
• User mode
• Kernel mode
• A bit, called the mode bit, is added to the hardware of the computer to
indicate the current mode: kernel (0) or user (1).
Mode bit (0 or 1) provided by hardware
• Provides ability to distinguish when system is running user code or
kernel code
• Some instructions designated as privileged, only executable in kernel
mode
• Systems call by a user asking the OS to perform some function
changes from user mode to kernel mode.
• Return from a system call resets the mode to user mode.
Transition from User to Kernel Mode
At system boot time, the hardware starts in kernel mode. The operating
system is then loaded and starts user applications in user mode.
Whenever a trap or interrupt occurs, the hardware switches from user
mode to kernel mode (that is, changes the state of the mode bit to 0).
Thus, whenever the operating system gains control of the computer, it is
in kernel mode. The system always switches to user mode (by setting the
mode bit to 1) before passing control to a user program
Timer
To prevent process to be in infinite loop (process hogging resources),
a timer is used, which is a hardware device.
83
Process Management Activities
The operating system is responsible for the following activities in
connection with process management:
One of the major advantage of having monolithic kernel is that it provides CPU
scheduling, memory management, file management and other operating system
functions through system calls.
The other one is that it is a single large process running entirely in a single address
space.
It is a single static binary file. Example of some Monolithic Kernel based OSs are:
Unix, Linux.
One of the major disadvantage of monolithic kernel is that, if anyone service fails
it leads to entire system failure.
If user has to add any new service. User needs to modify entire operating system.
Modularity Approach
The monolithic approach results in a situation where changes to one part of
the system can have wide-ranging effects to other parts.
messages messages
microkernel
hardware
Modules
Most modern operating systems implement kernel modules
• Uses object-oriented approach
• Each core component is separate
• Each talks to the others over known interfaces
• Each is loadable as needed within the kernel
106
Components of the Boot Process
The BIOS
The BIOS is the lowest level of software that interfaces with the hardware as a
whole.
The BIOS code is baked into the motherboard of your PC, usually stored on
what is called an EEPROM and is considerably hardware-specific.
Once your PC has been powered on, the BIOS begins its work as part of the
POST (Power-On Self Test) process.
During the POST procedure, quick tests are conducted where possible, and
errors caused by incompatible hardware, disconnected devices, or failing
components are often caught.
BIOS Boot Handoff: Provide option to go in boot setting.
In last, BIOS will load a very small program from the first hard disk to the
memory and tell the CPU to execute its contents. This hard drive is known as
“the boot device,” “startup disk,” or “drive 0” and can usually be picked or set in
the BIOS setup.
The BIOS loads the first 512 bytes from the hard drive of the selected boot
device – these 512 bytes are what is commonly known as the MBR, or the
107
Master Boot Record.
Components of the Boot Process
The Master Boot Record (MBR)
The Master Boot Record (MBR) is the information in the first sector of any
hard disk or diskette that identifies how and where an operating system is located
so that it can be boot (loaded) into the computer's main storage or random access
memory
Size of MBR is 512 bytes
The MBR also contains a very important bit of code known as the “bootstrap
code” which is called first stage boot loader. It look up the active partition from
the partition table, and load that code into the memory for execution by the CPU
as the next link in the boot chain.
It loads the first sector of the active partition, meaning another 512 bytes
108
Components of the Boot Process
The Partition Boot Sector
The bootstrap code in the MBR will usually load a sequence of bytes from the start of the
active partition. The exact layout of a partition depends what filesystem the partition has
been created or formatted with, but generally looks something like in the figure
The MBR loads the first 512 bytes of the active partition into the memory and instructs
the CPU to execute them.
The very first (three) bytes of the partition bootsector contain a single JMP instruction,
telling the CPU to skip xx bytes ahead and execute the next stage of the bootloader from
there.
The CPU follows the JMP instruction and seeks to the beginning of the bootstrap code
contained within the partition bootsector, and starts to execute. This bootstrap code is
called second stage bootloader.
The second-stage bootloader looks up a file stored on the partition itself (as a regular file),
and tells the CPU to execute its contents to begin the final part of the boot process.
109
Components of the Boot Process
The Bootloader
The PC has been handed-off from the BIOS to the bootstrap code in the MBR
and from the MBR to the bootstrap code in the partition bootsector, and from
there to the executable boot files on the active partition.
The actual logic involved in determining which operating system to load, where
to load it from, which parameters/options to pass on to it, and completing any
interactions with the user that might be available, the actual process of starting
the operating system begins.
110
Booting Process
111
112
UEFI-GPT Booting Process
UEFI stands for Unified Extensible Firmware Interface.
It does the same job as a BIOS, but with one basic difference: it
stores all data about initialization and startup in an .efi file, instead
of storing it on the firmware.
This .efi file is stored on a special partition called EFI System
Partition (ESP) on the hard disk. This ESP partition also contains
the bootloader.
UEFI was designed to overcome many limitations of the old BIOS,
including:
113
UEFI-GPT Booting Process
UEFI supports drive sizes upto 9 zettabytes, whereas BIOS only
supports 2.2 terabytes.
UEFI provides faster boot time.
UEFI offers security like "Secure Boot", which prevents the
computer from booting from unauthorized/unsigned applications.
UEFI runs in 32bit or 64bit mode, whereas BIOS runs in 16bit
mode. So UEFI is able to provide a GUI (navigation with mouse)
as opposed to BIOS which allows navigation only using the
keyboard.
BIOS uses the Master Boot Record (MBR) to save information
about the hard drive data while UEFI uses the GUID partition table
(GPT). The major difference between the two is that MBR uses 32-
bit entries in its table which limits the total physical partitions to
only 4. 114
UEFI supports larger HDDs and SDDs. UEFI’s theoretical size
limit for bootable drives is more than nine zettabytes, while BIOS
can only boot from drives 2.2 terabytes or smaller.
With GPT, you can create theoretically unlimited partitions on the
hard disk, even though it is generally restricted to 128 partitions by
most Oses
Unlike MBR that limits each partition to only 2TB in size, each
partition in GPT can hold up to 2^64 blocks in length (as it is using
64-bit), which is equivalent to 9.44ZB for a 512-byte block (1 ZB
is 1 billion terabytes). In Microsoft Windows, that size is limited to
256TB.
115
Why Choose UEFI?
One reason to choose this over the more familiar BIOS is that Intel
no longer intends to support the “traditional” BIOS in 2020.
UEFI provides the following functionality and advantages:
Languages: BIOS is written in assembler, while UEFI is written in simpler C-
language.
Drives: UEFI supports larger HDDs and SDDs. UEFI’s theoretical size limit for
bootable drives is more than nine zettabytes, while BIOS can only boot from
drives 2.2 terabytes or smaller.
Boot time: In most cases, UEFI provides a faster booting time for the operating
system.
Security: UEFI offers improved security features. “Secure Boot” prevents the
computer from booting from unsigned or unauthorized applications.
Data processors: UEFI runs in 32-bit or 64-bit mode. BIOS runs only in 16-bit
mode and may utilize only 1 MB of executable memory.
GUI: UEFI provides a more intuitive graphical user interface that you may
navigate with a mouse and keyboard, unlike BIOS. 116
Computer System Architecture
Based on General Purpose Processors
• Single processor
• Multiprocessor
• Clustering
Single Processor System
System have only one General Purpose CPU.
Multicore processors
Symmetric Multiprocessing Architecture
Multicore Systems
Most CPU design now includes multiple computing cores on a
single chip. Such multiprocessor systems are termed multicore.
Multicore systems can be more efficient than multiple chips
with single cores because:
• On-chip communication is faster than between-chip communication.
• One chip with multiple cores uses significantly less power than multiple
single-core chips, an important issue for laptops as well as mobile
devices.