Unit 1
Unit 1
TECHNOLOGY, CHENNAI.
UNIT I SYLLABUS
✔ OS is a control program
Controls execution of programs to prevent errors and improper use of
the computer
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
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
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
Computer-System Operation
Interrupt Handling
Interrupt Timeline
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
I/O Structure
❑ 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
❑ 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
❑ OS indexes into I/O device table to determine device status and to modify table
entry to include interrupt
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
Storage Definitions and Notation Review
The basic unit of computer storage is the bit. A bit can contain one of two values, 0 and 1.
All other storage in a computer is based on collections of bits. Given enough bits, it is
amazing how many things a computer can represent: numbers, letters, images, movies,
sounds, documents, and programs, to name a few. A byte is 8 bits, and on most computers
it is the smallest convenient chunk of storage. For example, most computers don’t have an
instruction to move a bit but do have one to move a byte. A less common term is word,
which is a given computer architecture’s native unit of data. A word is made up of one or
more bytes. For example, a computer that has 64-bit registers and 64-bit memory
addressing typically has 64-bit (8-byte) words. A computer executes many operations in its
native word size rather than a byte at a time.
Computer storage, along with most computer throughput, is generally measured and
manipulated in bytes and collections of bytes.
A kilobyte, or KB, is 1,024 bytes
a megabyte, or MB, is 1,0242 bytes
a gigabyte, or GB, is 1,0243 bytes
a terabyte, or TB, is 1,0244 bytes
a petabyte, or PB, is 1,0245 bytes
Computer manufacturers often round off these numbers and say that a megabyte is 1 million
bytes and a gigabyte is 1 billion bytes. Networking measurements are an exception to this
general rule; they are given in bits (because networks move data a bit at a time).
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
Storage Structure
❑ Main memory – only large storage media that the CPU can
access directly
❑ Random access
❑ Typically volatile
❑ Secondary storage – extension of main memory that provides
large nonvolatile storage capacity
❑ Hard 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
❑ Solid-state disks – faster than hard disks, nonvolatile
❑ Various technologies
❑ Becoming more popular
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
Storage Hierarchy
Storage-Device Hierarchy
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
Caching
✔ Important principle, performed at many levels in a computer (in
hardware, operating system, software)
✔ Information in use copied from slower to faster storage temporarily
✔ 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
✔ Cache smaller than storage being cached
✔ Cache management important design problem
✔ Cache size and replacement policy
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
Computer-System Architecture
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
✔ Some clusters are for high-performance computing (HPC)
✔ Applications must be written to use parallelization
✔ Some have distributed lock manager (DLM) to avoid conflicting
operations
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
Clustered Systems
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
Operating-System Operations
❑ Interrupt driven (hardware and software)
❑Hardware interrupt by one of the devices
❑Software interrupt (exception or trap):
❑Software error (e.g., division by zero)
❑Request for operating system service
❑Other process problems include infinite loop,
processes modifying each other or the operating
system
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
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
❖ Process termination requires reclaim of any reusable resources
❖ Single-threaded process has one program counter specifying location
of next instruction to execute
❖ Process executes instructions sequentially, one at a time, until completion
❖ Multi-threaded process has one program counter per thread
❖ Typically system has many processes, some user, some operating
system running concurrently on one or more CPUs
❖ Concurrency by multiplexing the CPUs among the processes / threads
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
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.
Memory management determines what is in memory and when
Optimizing CPU utilization and computer response to users
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
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
Storage Management
✔ OS provides uniform, logical view of information storage
✔ Abstracts physical properties to logical storage unit - file
✔ Each medium is controlled by device (i.e., disk drive, tape drive)
✔ Varying properties include access speed, capacity, data-transfer rate, access
method (sequential or random)
✔ 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 directories
✔ Mapping files onto secondary storage
✔ Backup files onto stable (non-volatile) storage media
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
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)
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
I/O Subsystem
Touchscreen Interfaces
▪ Touchscreen devices require
new interfaces
▪ Mouse not possible or not desired
▪ Actions and selection based on
gestures
▪ Virtual keyboard for text entry
▪ Voice commands.
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
System Calls
▪ System calls are the fundamental interfaces provided by an
operating system (OS) to allow user-level programs to interact with
the operating system's kernel.
▪ They provide a way for applications to request services from the
OS, such as performing I/O operations, managing processes,
accessing hardware, and more.
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
⮚ 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
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
❑ Protection
❑ Control access to resources
❑ Get and set permissions
❑ Allow and deny user access
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
Examples of Windows and Unix System Calls
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
Standard C Library Example
C program invoking printf() library call, which calls write()
system call
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
Example: MS-DOS
▪ Single-tasking
▪ Shell invoked when
system booted
▪ Simple method to run
program
▪ No process created
▪ Single memory space
▪ Loads program into
memory, overwriting all
but the kernel
▪ Program exit -> shell
reloaded
At system startup running a program
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
Example: FreeBSD
▪ Unix variant
▪ Multitasking
▪ User login -> invoke user’s choice of
shell
▪ Shell executes fork() system call to
create process
▪ Executes exec() to load program into
process
▪ Shell waits for process to terminate or
continues with user commands
▪ Process exits with:
▪ code = 0 – no error
▪ code > 0 – error code
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
System Programs
⮚ System programs provide a convenient environment for
program development and execution. They can be divided
into:
⮚ File manipulation
⮚ Status information sometimes stored in a File modification
⮚ Programming language support
⮚ Program loading and execution
⮚ Communications
⮚ Background services
⮚ Application programs
⮚ Most users’ view of the operation system is defined by
system programs, not the actual system calls.
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
System Programs
System programs are software applications that facilitate the proper
functioning of the computer system and assist users in managing the
hardware and software resources.
⮚ File management - Create, delete, copy, rename, print, dump, list,
and generally manipulate files and directories
⮚ Device Drivers: Device drivers are software components that
enable the OS to communicate with hardware devices like printers,
scanners, graphics cards, etc.
⮚ Task Schedulers: Task schedulers manage the execution of
processes and allocate system resources (such as CPU time and
memory) to different processes.
⮚ Memory Management Programs: These programs handle the
allocation and deallocation of memory for processes. They manage
virtual memory, ensuring that each process has access to the
memory it needs without interfering with other processes.
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
Implementation
⮚ Much variation
⮚ Early OSes in assembly language
⮚ Then system programming languages like Algol, PL/1
⮚ Now C, C++
⮚ Actually usually a mix of languages
⮚ Lowest levels in assembly
⮚ Main body in C
⮚ Systems programs in C, C++, scripting languages like PERL, Python, shell
scripts
⮚ More high-level language easier to port to other hardware
⮚ But slower
⮚ Emulation can allow an OS to run on non-native hardware
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
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.
With modularity, layers are selected
such that each uses functions
(operations) and services of only
lower-level layers
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
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
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
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)
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
Mac OS X Structure
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
iOS
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
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
Android Architecture
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
Operating-System Debugging
⮚ Debugging is finding and fixing errors, or bugs
⮚ OS generate log files containing error information
⮚ Failure of an application can generate core dump file capturing
memory of the process
⮚ Operating system failure can generate crash dump file
containing kernel memory
⮚ Beyond crashes, performance tuning can optimize system
performance
⮚ Sometimes using trace listings of activities, recorded for analysis
⮚ Profiling is periodic sampling of instruction pointer to look for statistical
trends
⮚ Kernighan’s Law: “Debugging is twice as hard as writing the
code in the first place. Therefore, if you write the code as
cleverly as possible, you are, by definition, not smart enough to
debug it.”
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
Performance Tuning
⮚ Improve performance by
removing bottlenecks
⮚ OS must provide means of
computing and displaying
measures of system behavior
⮚ For example, “top” program
or Windows Task Manager
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
DTrace
● DTrace tool in Solaris, FreeBSD,
Mac OS X allows live
instrumentation on production
systems
● Probes fire when code is
executed within a provider,
capturing state data and
sending it to consumers of
those probes
● Example of following
XEventsQueued system call
move from libc library to kernel
and back
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
Dtrace (Cont.)
● DTrace code to record amount
of time each process with
UserID 101 is in running mode
(on CPU) in nanoseconds
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
System Boot
✔ When power initialized on system, execution starts at a fixed
memory location
✔ Firmware ROM used to hold initial boot code
✔ Operating system must be made available to hardware so hardware
can start it
✔ Small piece of code – bootstrap loader, stored in ROM or EEPROM locates
the kernel, loads it into memory, and starts it
✔ Sometimes two-step process where boot block at fixed location loaded by
ROM code, which loads bootstrap loader from disk
✔ Common bootstrap loader, GRUB, allows selection of kernel from
multiple disks, versions, kernel options
✔ Kernel loads and system is then running
SRM INSTITUTE OF SCIENCE AND
TECHNOLOGY, CHENNAI.
References
1. Abraham Silberschatz, Peter Baer Galvin, Greg Gagne,
Operating systems, 10th ed., John Wiley & Sons, 2018.
Thank You!