OS-Module-I
OS-Module-I
Objectives
To describe the basic organization of computer systems
To provide a grand tour of the major components of operating systems
To give an overview of the many types of computing environments
To explore several operating systems
2
What is an Operating System?
3
Computer System Structure
Computer system can be divided into four components:
Operating system
Controls and coordinates use of hardware among various
applications and users
Users
People, machines, other computers
4
Four Components of a Computer System
5
What Operating Systems Do
Users want convenience, ease of use and good performance
Don’t care about resource utilization
But shared computer such as mainframe or minicomputer must keep all
users happy
Users of dedicated systems such as workstations have dedicated
resources but frequently use shared resources from servers
Handheld computers are resource poor, optimized for usability and battery
life
Some computers have little or no user interface, such as embedded
computers in devices and automobiles
6
Operating System Definition
OS is a resource allocator
Decides between conflicting requests for efficient and fair resource use
OS is a control program
7
Operating System Definition (Cont.)
No universally accepted definition
“The one program running at all times on the computer” is the kernel.
an application program.
8
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
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
10
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
Interrupt Handling
The operating system preserves the state of the CPU by storing registers
and the program counter
Determines which type of interrupt has occurred:
polling
vectored interrupt system
Separate segments of code determine what action should be taken for each
type of interrupt
11
Interrupt Timeline
12
Storage Structure
Main memory – only large storage media that the CPU can access directly
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
Solid-state disks – faster than hard disks, nonvolatile
store data permanently inside an integrated circuit, typically using
flash memory.
13
Storage Hierarchy
Storage systems organized in hierarchy
Speed
Cost
Volatility
Caching – copying information into faster storage system; main memory can
be viewed as a cache for secondary storage
14
Storage-Device Hierarchy
15
Caching
Important principle, performed at many levels in a computer (in hardware,
operating system, software)
16
Direct Memory Access Structure
Used for high-speed I/O devices able to transmit information at close to
memory speeds
Only one interrupt is generated per block, rather than the one interrupt per
byte
17
How a Modern Computer Works
I/O Structure:
A device controller maintains some
local buffer storage and a set of
special-purpose registers.
The device controller is responsible for
moving the data between the
peripheral devices that it controls and
its local buffer storage.
Typically, an operating systems have a
device driver for each device controller.
This device driver understands the
device controller and provides the rest
of the operating
system with a uniform interface to the
device.
18
Real-time Scenario for (threads)?
Thread: the smallest unit of execution within a process
Gaming Applications
19
Computer-System Architecture
Most systems use a single general-purpose processor
Advantages include:
Increased throughput
Economy of scale
Increased reliability – graceful degradation or fault tolerance
Two types:
Asymmetric Multiprocessing – is a system architecture where each
processor is assigned a specific task and operates independently.
one processor acting as the master to coordinate the work of the others kind of
master-slave architecture.
Symmetric Multiprocessing – all processors share equal responsibility and work
collaboratively
20
Symmetric Multiprocessing Architecture
21
A Dual-Core Design
Multi-core/Dual-Core
Systems containing all chips
Chassis containing multiple separate systems
22
Multi-core vs Multi-processor?
Multi-core
A single CPU (chip) with multiple cores, where each core can execute tasks independently.
A quad-core processor has 4 cores, each capable of running its own task simultaneously.
Examples:
Intel Core i7: A CPU with 8 cores, commonly found in laptops and desktops.
AMD Ryzen 9 5900X: A 12-core CPU for gaming and productivity tasks.
Use Case:
Multicore processors are used in devices requiring parallelism for multitasking, gaming,
video editing, AI inference, and general-purpose computing.
Multi-Processor:
23
Multi-core vs Multi-processor?
24
Clustered Systems
Like multiprocessor systems, but multiple systems working together
Usually sharing storage via a storage-area network (SAN)
25
Clustered Systems
26
Operating System Structure
An operating system provides the environment within which programs are
executed.
Multiprogramming (Batch system) needed for efficiency
Single user cannot keep CPU and I/O devices busy at all times
Multiprogramming organizes jobs (code and data) so CPU always has one to
execute
When it has to wait (for I/O for example), OS switches to another job
27
Operating System Structure
Timesharing (multitasking) is logical extension of multiprogramming.
CPU switches jobs so frequently that users can interact with each job while it is
running, creating interactive computing
If processes don’t fit in memory, swapping moves them in and out to run
28
Memory Layout for Multiprogrammed System
29
Operating-System Operations
Interrupt driven (hardware and software)
30
Operating-System Operations (cont.)
Dual-mode operation allows OS to protect itself and other system
components
System call changes mode to kernel, return from call resets it to user
31
Transition from User to Kernel Mode
32
Operating-System Operations (cont.)
Privilege Level Low privilege (restricted access). High privilege (full system access).
No direct hardware access; must use system calls to Direct access to hardware (CPU, memory,
Access to Hardware
interact with hardware. devices).
Execution Scope Executes application code. Executes critical OS code and services.
33
fi
Privileged Instructions?
Privileged Instructions are special instructions that can only be executed in kernel mode
(also called supervisor mode or system mode) of an operating system.
These instructions have a direct impact on the hardware or the operating system itself.
Potentially harm the system's stability or security if executed by an unprivileged user program
Examples:
I/O Operations:
Directly accessing hardware devices, such as reading or writing to I/O ports or controlling
disk drives.
Example: Initiating a disk read/write operation.
Setting or Changing System Configuration:
Modifying the CPU mode, enabling or disabling interrupts, or altering memory settings.
Example: Changing the base address of a page table.
Interrupt Management:
Enabling, disabling, or servicing interrupts.
Example: cli (clear interrupt flag) and sti (set interrupt flag) instructions in x86
processors.
34
Real-time Scenarios?
User Mode
Kernel Mode
35
A View of Operating System Services
36
Process Management
A process is a program in execution.
Typically system has many processes, some user, some operating system running
concurrently on one or more CPUs
38
Memory Management
To execute a program all (or part) of the instructions must be in memory
All (or part) of the data that is needed by the program must be in memory.
Deciding which processes (or parts thereof) and data to move into and
out of memory
39
Storage Management
OS provides uniform, logical view of information storage
File-System management
OS activities include
Creating and deleting files and directories
Primitives to manipulate files and directories
Mapping files onto secondary storage
Backup files onto stable (non-volatile) storage media
40
Mass-Storage Management
Usually disks used to store data that does not fit in main memory or data that
must be kept for a “long” period of time
Proper management is of central importance
Entire speed of computer operation hinges on disk subsystem and its
algorithms
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)
41
Migration of data “A” from Disk to Register
Multitasking environments must be careful to use most recent value, no
matter where it is stored in the storage hierarchy
42
I/O Subsystem
One purpose of OS is to hide peculiarities of hardware devices from the user
I/O subsystem responsible for
43
Protection and Security
User identities (user IDs, security IDs) include name and associated
number, one per user
44
Operating System Services
Operating systems provide an environment for execution of programs and services to
programs and users
One set of operating-system services provides functions that are helpful to the user:
User interface - Almost all operating systems have a user interface (UI).
Varies between Command-Line (CLI), Graphics User Interface (GUI),
Batch
Program execution - The system must be able to load a program into memory
and to run that program, end execution, either normally or abnormally (indicating
error)
I/O operations - A running program may require I/O, which may involve a file or
an I/O device
45
Bourne Shell Command Interpreter
46
User Operating System Interface - GUI
User-friendly desktop metaphor interface
Various mouse buttons over objects in the interface cause various actions
(provide information, options, execute function, open directory (known as a
folder)
Apple Mac OS X is “Aqua” GUI interface with UNIX kernel underneath and
shells available
Unix and Linux have CLI with optional GUI interfaces (CDE, KDE, GNOME)
47
Touchscreen Interfaces
48
The Mac OS X GUI
49
System Calls
A system call is a mechanism that allows user-level programs to request
services from the operating system kernel.
Three most common APIs are Win32 API for Windows, POSIX API for
POSIX-based systems (including virtually all versions of UNIX, Linux, and
Mac OS X), and Java API for the Java virtual machine (JVM)
50
Why Are System Calls Needed?
User programs run in user mode, where they have limited access
to hardware and system resources.
To perform privileged operations (like accessing files, allocating
memory, or interacting with hardware), programs must use system
calls, which execute in kernel mode.
For example:
A program cannot directly access disk storage; it must use a
system call like read() or write().
A program cannot directly create processes; it must use
fork().
51
Example of System Calls
System call sequence to copy the contents of one file to another file
52
Example of Standard API
53
System Call Implementation
Typically, a number associated with each system call
The caller need not to know anything about how the system call is
implemented
Just needs to obey API and understand what OS will do as a result call
54
API – System Call – OS Relationship
55
API – System Call – OS Relationship
APIs act as wrappers around system calls to simplify their use.
the API internally calls the relevant system call (sys_open() in Linux).
The OS kernel processes the system call and returns the result to the API,
which then gives it back to the application.
56
System Call Parameter Passing
Often, more information is required than simply identity of desired system call
Block and stack methods do not limit the number or length of parameters
being passed
57
Types of System Calls
Process control
create process, terminate process
end, abort
load, execute
58
Types of System Calls
File management
create file, delete file
open, close file
read, write, reposition
get and set file attributes
Device management
request device, release device
read, write, reposition
get device attributes, set device attributes
logically attach or detach devices
59
Types of System Calls (Cont.)
Information maintenance
get time or date, set time or date
get system data, set system data
get and set process, file, or device attributes
Communications
create, delete communication connection
send, receive messages if message passing model to host name or
process name
From client to server
Shared-memory model create and gain access to memory regions
transfer status information
attach and detach remote devices
Protection
Control access to resources
Get and set permissions
Allow and deny user access
60
Examples of Windows and Unix System Calls
61
Operating System Structure
General-purpose OS is very large program
Layered – an abstraction
Microkernel -Mach
62
Simple Structure -- Monolithic
A monolithic OS is an operating system where the entire kernel runs in a
single address space with all essential services tightly integrated.
This structure provides high performance but can be complex and difficult to
maintain.
Characteristics
63
Simple Structure -- MS-DOS
64
Non Simple Structure -- UNIX
Systems programs
The kernel
Consists of everything below the system-call interface and above the
physical hardware
65
Traditional UNIX System Structure
Beyond simple but not fully layered
66
Layered Approach
The operating system is divided into a
number of layers (levels), each built
on top of lower layers. The bottom
layer (layer 0), is the hardware; the
highest (layer N) is the user interface.
67
What’s the Layered Approach for I/O looks like?
User Interface Layer: User requests I/O operations through GUI/CLI
(GUI/CLI: File Explorer, Terminal, Browser)
System Call Interface (SCI) Layer : Converts API requests into system calls
(System Calls: sys_read(), sys_write())
Device Driver Layer: Translates I/O requests into low-level hardware commands
(Disk Driver, Network Driver, Printer Driver)
68
Microkernel System Structure
Moves as much from the kernel into user space
Mach example of microkernel
Mac OS X kernel (Darwin) partly based on Mach
69
Microkernel System Structure
70
Modules
Many modern operating systems implement loadable 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
Overall, similar to layers but with more flexible
Linux, Solaris, etc
71
Solaris Modular Approach
72
Hybrid Systems
Most modern operating systems are actually not one pure model
Hybrid combines multiple approaches to address performance, security,
usability needs
Linux and Solaris kernels in kernel address space, so monolithic, plus
modular for dynamic loading of functionality
Windows mostly monolithic, plus microkernel for different subsystem
personalities
Apple Mac OS X hybrid, layered, Aqua UI plus Cocoa programming
environment
Below is kernel consisting of Mach microkernel and BSD Unix parts, plus
I/O kit and dynamically loadable modules (called kernel extensions)
73
Mac OS X Structure
74
iOS
75
Android
Developed by Open Handset Alliance (mostly Google)
Open Source
Similar stack to IOS
Based on Linux kernel but modified
Provides process, memory, device-driver management
Adds power management
Runtime environment includes core set of libraries and Dalvik virtual machine
Apps developed in Java plus Android API
Java class files compiled to Java bytecode then translated to
executable than runs in Dalvik VM
Libraries include frameworks for web browser (webkit), database (SQLite),
multimedia, smaller libc
76
Android Architecture
77
Summary