Introduction
Operating Systems (CS-220)
Spring 2021, FAST NUCES
Google Classroom Code: dpjhurs
COURSE SUPERVISOR: ANAUM HAMID
[email protected]
Spring 2021 1
Course Outline
Hardware
Before mid 1
Deadlock/ Process/
Disk scheduling
Scheduling Before and
After mid2 after mid 1
Linux Scripting
C/C# programming
Memory Multithreading/
Synchronization
Before and
after mid 2 mid 2
Spring 2021 2
COURSE SUPERVISOR: ANAUM HAMID
Evaluation Instruments and Marks Distributions
• Assignments = 20 marks
• Project = 10 marks
• Midterm = 30 marks (15 for each)
• Final Term = 50 marks
• Total = 100 Marks
Spring 2021 3
COURSE SUPERVISOR: ANAUM HAMID
Course Recourses
TEXTBOOK:
• Operating Systems Concepts, 10th edition, by Abraham
Silberschatz, Peter Baer Galvin, and Greg Gagne.
REFERENCE BOOKS:
• Operating Systems – Internals and Design Principles, 8th
edition, by William Stallings.
Spring 2021 4
COURSE SUPERVISOR: ANAUM HAMID
Introduction
Road Map.
1. What is an Operating System?
2. CS structures.
3. Interrupt
4. I/O
5. Memory
6. CS Architecture
7. Clustered Systems
8. OS Structure + Operations
9. Computing Environments
FALL 2020 5
COURSE SUPERVISOR: ANAUM HAMID
Operating System: Overview
• Operating system (OS): a system software that exploits the
hardware resources to provide a set of services to system users.
• The OS manages the processor(s), memory and input/output
(I/O) devices on behalf of its users.
• Note: it is important to have some fundamental understanding of
basic data structures, computer organization and a high-level
programming language, such as C or Java, before examining
topics related to operating systems.
Spring 2021 6
COURSE SUPERVISOR: ANAUM HAMID
Operating System: Overview (Cont.)
Relationship between application software and system software
Spring 2021 7
COURSE SUPERVISOR: ANAUM HAMID
Computer System Structure
• Computer system can be divided into four
components:
1. Hardware – provides basic computing
resources
2. Operating system
3. Application programs
4. Users
Spring 2021 8
COURSE SUPERVISOR: ANAUM HAMID
Spring 2021
Four Components
of a Computer
System
9
COURSE SUPERVISOR: ANAUM HAMID
Operating System Definition
• OS is a resource allocator
– Manages all resources
– Decides between conflicting requests for
efficient and fair resource use
• OS is a control program
– Controls execution of programs to prevent
errors and improper use of the computer
Spring 2021 10
COURSE SUPERVISOR: ANAUM HAMID
Computer Startup
• bootstrap program is loaded at power-up or
reboot
– Typically stored in ROM or EPROM, generally
known as firmware
– Initializes all aspects of system
– Loads operating system kernel and starts
execution
Spring 2021 11
COURSE SUPERVISOR: ANAUM HAMID
• Computer-system operation
• One or more CPUs, device controllers
connect through common bus providing
access to shared memory
• Concurrent execution of CPUs and
devices competing for memory cycles
Computer
System
Organization
Spring 2021 12
COURSE SUPERVISOR: ANAUM HAMID
Spring 2021
• I/O devices and the CPU can execute
concurrently
• Each device controller is in charge of a
particular device type
Computer- • Each device controller has a local buffer
System
• CPU moves data from/to main memory
Operation to/from local buffers
• I/O is from the device to local buffer of
controller
• Device controller informs CPU that it has
finished its operation by causing an
INTERRUPT
13
COURSE SUPERVISOR: ANAUM HAMID
Interrupts
• Interrupt: a mechanism by which other modules (I/O, memory)
may interrupt the “normal sequencing of the processor”.
• Most common classes of Interrupts are:
Generated by an I/O controller, to signal normal completion of
I/O
an operation or to signal a variety of error conditions.
Generated by a condition that occurs as a result of an
instruction execution, such as arithmetic overflow, division by
Program
zero, attempt to execute an illegal machine instruction, and
reference outside a user’s allowed memory space.
Timer Generated by a timer within the processor.
Hardware failure Generated by a failure, such as memory error.
FALL 2020 14
COURSE SUPERVISOR: ANAUM HAMID
Common Functions of Interrupts
● Interrupt transfers control to the interrupt
service routine generally, through the
interrupt vector, which contains the
addresses of all the service routines
● Interrupt architecture must save the
address of the interrupted instruction
● A trap or exception is a software-
generated interrupt caused either by an
error or a user request
● An operating system is interrupt driven
Spring 2021 15
COURSE SUPERVISOR: ANAUM HAMID
Interrupt Handling
1. The operating system preserves the state of the
CPU by storing registers and the program
counter
2. Determines which type of interrupt has
occurred:
1. polling
2. vectored interrupt system
3. Separate segments of code determine what
action should be taken for each type of
interrupt
Spring 2021 16
COURSE SUPERVISOR: ANAUM HAMID
Multiple Interrupts
FALL 2020 17
COURSE SUPERVISOR: ANAUM HAMID
I/O Structure
1. After I/O starts, control returns to user program only
upon I/O completion
◦ Wait instruction idles the CPU until the next interrupt
◦ Wait loop (contention for memory access)
◦ At most one I/O request is outstanding at a time, no
simultaneous I/O processing.
2. After I/O starts, control returns to user program without
waiting for I/O completion
◦ System call – request to the OS to allow user to wait for I/O
completion
◦ Device-status table contains entry for each I/O device indicating
its type, address, and state
Spring 2021 18
COURSE SUPERVISOR: ANAUM HAMID
Direct Memory Access Structure
➢ Used for high-speed I/O devices able to transmit information at close to
memory speeds
➢ Device controller transfers blocks of data from buffer storage directly to
main memory without CPU intervention
➢ Only one interrupt is generated per block, rather than the one interrupt per
byte
Spring 2021 19
COURSE SUPERVISOR: ANAUM HAMID
Memory
Spring 2021 20
Storage Structure
1. Main memory – only large storage media that the
CPU can access directly
2. Secondary storage – extension of main memory that
provides large nonvolatile storage capacity.
3. Magnetic disks – rigid metal or glass platters covered
with magnetic recording material
◦ Disk surface is logically divided into tracks, which are
subdivided into sectors
◦ The disk controller determines the logical interaction between
the device and the computer
Spring 2021 21
COURSE SUPERVISOR: ANAUM HAMID
Storage Hierarchy
Storage systems organized in hierarchy
◦ Speed
◦ Cost
◦ Volatility
1. Caching – copying information into faster storage
system; main memory can be viewed as a cache for
secondary storage
2. Device Driver for each device controller to manage I/O
◦ Provides uniform interface between controller and kernel
Spring 2021 22
COURSE SUPERVISOR: ANAUM HAMID
Storage-Device Hierarchy
Spring 2021 23
COURSE SUPERVISOR: ANAUM HAMID
FALL 2020 24
COURSE SUPERVISOR: ANAUM HAMID
Caching
1. Important principle, performed at many
levels in a computer (in hardware,
operating system, software).
2. Faster storage (cache) checked first to
determine if information is there
◦ If it is, information used directly from the cache
(fast)
◦ If not, data copied to cache and used there
Spring 2021 25
COURSE SUPERVISOR: ANAUM HAMID
Computing Architectures
Spring 2021 26
Computer-System Architecture
• Multiprocessor systems growing in use and
importance
– Also known as parallel systems, tightly-coupled
systems
– Advantages include:
1. Increased throughput
2. Economy of scale
3. Increased reliability – graceful degradation or fault
tolerance
– Two types:
1. Asymmetric Multiprocessing
2. Symmetric Multiprocessing
Spring 2021 27
COURSE SUPERVISOR: ANAUM HAMID
Symmetric vs. Asymmetric Multiprocessing Architecture
Spring 2021 28
COURSE SUPERVISOR: ANAUM HAMID
A Dual-Core Design
• UMA and NUMA architecture variations
• Multi-chip and multicore
Spring 2021 29
COURSE SUPERVISOR: ANAUM HAMID
Clustered Systems
• Like multiprocessor systems, but multiple
systems working together
– Usually sharing storage via a storage-area network
(SAN)
– Provides a high-availability service which survives
failures
• Asymmetric clustering has one machine in hot-standby
mode
• Symmetric clustering has multiple nodes running
applications, monitoring each other
Spring 2021 30
COURSE SUPERVISOR: ANAUM HAMID
Clustered Systems
Spring 2021 31
COURSE SUPERVISOR: ANAUM HAMID
Operating System
Structures + Operations
Spring 2021 32
Operating System Structure
• Multiprogramming needed for efficiency
❖ Single user cannot always keep CPU and I/O devices busy
❖ Multiprogramming organizes jobs (code and data) so CPU always has one to execute
❖ A subset of total jobs in system is kept in memory
❖ One job selected and run via job scheduling
❖ When it must wait (for I/O for example), OS switches to another job
• Timesharing (multitasking) is logical extension in which CPU switches jobs so frequently that users can interact
with each job while it is running, creating interactive computing
❖ Response time should be < 1 second
❖ Each user has at least one program executing in memory process
❖ If several jobs ready to run at the same time CPU scheduling
❖ If processes don’t fit in memory, swapping moves them in and out to run
❖ Virtual memory allows execution of processes not completely in memory
Spring 2021 33
COURSE SUPERVISOR: ANAUM HAMID
Memory Layout for Multiprogram System
Spring 2021 34
COURSE SUPERVISOR: ANAUM HAMID
• Dual-mode operation allows OS to protect itself and
other system components
• User mode and kernel mode
• Mode bit provided by hardware
• Provides ability to distinguish when system is
Operating- running user code or kernel code
• Some instructions designated as privileged,
only executable in kernel mode
System • System call changes mode to kernel, return
from call resets it to user
Operations • Increasingly CPUs support multi-mode operations
• i.e. virtual machine manager (VMM) mode for
guest VMs.
• “The one program running at all times on the
computer” is the kernel.
Spring 2021 35
COURSE SUPERVISOR: ANAUM HAMID
• Timer to prevent infinite loop / process hogging
resources
• Set interrupt after specific period
• Operating system decrements counter
• When counter zero generate an interrupt
Transition • Set up before scheduling process to regain
control or terminate program that exceeds
from User to allotted time
Kernel
Mode
Spring 2021 36
Process Management
• A process is a program in execution. It is a unit of work
within the system. Program is a passive entity; process is an
active entity.
• Process needs resources to accomplish its task
– CPU, memory, I/O, files
– Initialization data
• Program counter (PC): Contains the address of an
instruction to be fetched
• Single-threaded process has one program counter
specifying location of next instruction to execute
• Multi-threaded process has one program counter per
thread
Spring 2021 37
COURSE SUPERVISOR: ANAUM HAMID
Process Management Activities
The operating system is responsible for the following activities in
connection with process management:
• Creating and deleting both user and system processes
• Suspending and resuming processes
• process synchronization
• process communication
• deadlock handling
Spring 2021 38
COURSE SUPERVISOR: ANAUM HAMID
Memory Management
• Memory management activities
– Keeping track of which parts of memory are
currently being used and by whom
– Deciding which processes (or parts thereof)
and data to move into and out of memory
– Allocating and deallocating memory space as
needed
Spring 2021 39
COURSE SUPERVISOR: ANAUM HAMID
Storage Management
• File-System management
– Files usually organized into directories
– Access control on most systems to determine
who can access what
– OS activities include
• Creating and deleting files and directories
• Primitives to manipulate files and dirs
• Mapping files onto secondary storage
• Backup files onto stable (non-volatile) storage media
Spring 2021 40
COURSE SUPERVISOR: ANAUM HAMID
Mass-Storage Management
• OS activities
– Free-space management
– Storage allocation
– Disk scheduling
• Some storage need not be fast
– Tertiary storage includes optical storage, magnetic tape
– Still must be managed – by OS or applications
– Varies between WORM (write-once, read-many-times) and RW
(read-write)
Spring 2021 41
COURSE SUPERVISOR: ANAUM HAMID
I/O Subsystem
• I/O subsystem responsible for
– Memory management of I/O
– caching (storing parts of data in faster storage
for performance)
– spooling (the overlapping of output of one job
with input of other jobs)
Spring 2021 42
COURSE SUPERVISOR: ANAUM HAMID
Protection and Security
• Protection – any mechanism for controlling access
of processes or users to resources defined by the OS
• Security – defense of the system against internal
and external attacks
– Huge range, including denial-of-service, worms, viruses,
identity theft, theft of service
Spring 2021 43
COURSE SUPERVISOR: ANAUM HAMID
Computing Environments
Spring 2021 44
Spring 2021
• Distributed
• Collection of separate, possibly heterogeneous,
systems networked together
Computing • Network is a communications path,
Environments • Local Area Network (LAN)
-Distributed
• Wide Area Network (WAN)
• Network Operating System provides features
between systems across network
45
COURSE SUPERVISOR: ANAUM HAMID
Spring 2021
Computing • Client-Server
Environments Computing
• Dumb terminals
– Client- supplanted by
smart PCs
Server • Many systems now
servers, responding
to requests
generated by clients
46
COURSE SUPERVISOR: ANAUM HAMID
Spring 2021
Computing • Another model of
distributed system
Environments
- Peer-to-Peer • P2P does not
distinguish clients and
servers
47
COURSE SUPERVISOR: ANAUM HAMID
Computing
Environments
– Cloud
Computing
Spring 2021 48
COURSE SUPERVISOR: ANAUM HAMID
Spring 2021
• Real-time embedded systems most prevalent form of
computers
• Vary considerable, special purpose, limited purpose
Real-Time OS, real-time OS
Embedded • Use expanding
• Many other special computing environments as well
Systems • Some have OSes, some perform tasks without an OS
• Real-time OS has well-defined fixed time constraints
• Processing must be done within constraint
• Correct operation only if constraints met
49
COURSE SUPERVISOR: ANAUM HAMID
Thank You!
Chapter 1 Completed
Spring 2021 50
COURSE SUPERVISOR: ANAUM HAMID