UNIT I
1. Operating System
A program that acts as an intermediary between a user of a computer and the computer
hardware
Operating system goals:
o Execute user programs and make solving user problems easier
o Make the computer system convenient to use
o Use the computer hardware in an efficient manner
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
Kernel - The one program running at all times on the computer
2. Computer System Structure
Computer system can be divided into four components:
o Hardware – provides basic computing resources
CPU, memory, I/O devices
o Operating system
Controls and coordinates use of hardware among various applications and
users
o Application programs – define the ways in which the system resources are used to
solve the computing problems of the users
Word processors, compilers, web browsers, database systems, video
games
o Users
People, machines, other computers
Four Components of a Computer System
Bootstrap Program
bootstrap program is loaded at power-up or reboot
o Typically stored in ROM or EPROM, generally known as firmware
o Initializes all aspects of system
o Loads operating system kernel and starts execution
3. Computer System Organization
Computer-system operation
o One or more CPUs, device controllers connect through common bus providing
access to shared memory
o Concurrent execution of CPUs and devices competing for memory cycles
Computer-System Operation
I/O devices and the CPU can execute concurrently
Each device controller is in charge of a particular device type
Each device controller has a local buffer
CPU moves data from/to main memory to/from local buffers
I/O is from the device to local buffer of controller
4. Interrupts
An interrupt is a signal to the processor emitted by hardware or software indicating an
event that needs immediate attention
Two types:
Hardware interrupts – raised by external hardware devices
Software interrupt – raised by user program
Eg:-Device controller informs CPU that it has finished its operation by causing an
interrupt
Common Functions of Interrupts
Interrupt transfers control to the interrupt service routine through the interruptvector
Interrupt vector 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:
o Polling - CPU keeps on checking I/O devices at regular interval whether it needs
CPU service
o vectored interrupt system - the I/O device interrupts the CPU and tell CPU that it
need CPU service
Separate segments of code determine what action should be taken for each type of
interrupt
Interrupt Timeline
5. I/O Structure
After I/O starts, control returns to user program only upon I/O completion
o Wait instruction idles the CPU until the next interrupt
o Wait loop (contention for memory access)
o 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
o System call – request to the OS to allow user to wait for I/O completion
o Device-status table contains entry for each I/O device indicating its type,
address, and state
o OS indexes into I/O device table to determine device status and to modify table
entry to include interrupt
6. Storage Structure
Storage structures are divided into
Main memory – only large storage media that the CPU can access directly
o Randomaccess
o 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
o Disk surface is logically divided into tracks, which are subdivided into sectors
o The disk controller determines the logical interaction between the device and the
computer
Solid-state disks – faster than hard disks, nonvolatile
Storage Hierarchy
Storage systems organized in hierarchy
o Speed
o Cost
o Volatility
Caching – copying information into faster storage system; main memory can be viewed
as a cache for secondary storage
Device Driver for each device controller to manage I/O
o Provides uniform interface between controller and kernel
Caching
Information in use copied from slower to faster storage temporarily
Faster storage (cache) checked first to determine if information is there
o If it is, information used directly from the cache (fast)
o If not, data copied to cache and used there
Cache smaller than storage being cached
o Cache management important design problem
o Cache size and replacement policy
7. Direct Memory Access
Interrupt-driven I/O is fine for moving small amounts of data but can produce high
overhead when used for bulk data movement such as disk I/O.
To solve this problem, direct memory access (DMA) is used.
The device controller transfers an entire block of data directly to or from its own buffer
storage to memory, with no intervention by the CPU.
Only one interrupt is generated per block, to tell the device driver that the operation has
completed, rather than the one interrupt per byte generated for low-speed devices.
While the device controller is performing these operations, the CPU is available to
accomplish other work.
Some high-end systems use switch rather than bus architecture. On these systems,
multiple components can talk to other components concurrently, rather than competing
for cycles on a shared bus. In this case, DMA is even more effective.
The following figure shows all components of a computer system
8. Computer-System Architecture
The following are types of computer system architecture
Single processor
Multiprocessor
Dual-core / multicore
Clustered system
i) Most systems use a single general-purpose processor
o Most systems have special-purpose processors as well
ii) Multiprocessors systems growing in use and importance
o Also known as parallel systems, tightly-coupled systems
o Such systems have two or more processors in close communication, sharing the computer
bus and sometimes the clock, memory, and peripheral devices.
o Multiprocessors appears in Servers currently used in Desktop.
o They appeared on mobile devices such as smart phones and tablet computers
Advantages
Increased throughput
By increasing the number of processors, we expect to get more work
done in less time.
Economy of scale
Multiprocessor systems can cost less than equivalent multiple single-
processor systems,because they can share peripherals, mass storage, and
power supplies.
Increased reliability – graceful degradation or fault tolerance
If we have ten processors and one fails, then each of the remaining nine
processors can pick up a share of the work of the failed processor. Thus,
the entire system runs only 10 percent slower, rather than failing
altogether.
o Two types:
Asymmetric Multiprocessing
Each processor is assigned a specie task.
A boss processor controls the system; the other processors either look to
the boss for instruction or have predefined tasks.
This scheme defines a boss–worker relationship.
The boss processor schedules and allocates work to the worker
processors.
Symmetric Multiprocessing
Each processor performs all tasks
SMP means that all processors are peers; no boss–worker relationship
exists between processors.
The following example shows the symmetric multiprocessing architecture
iii)Dual-Core Design
In response to the need for more computing performance, single-CPU systems evolved
into multi-CPU systems.
A more recent, in system design is to place multiple computing cores on a single chip.
Each core appears as a separate processor to the operating system.
Whether the cores appear across CPU chips or within CPU chips, we call these systems
multicore or multiprocessor systems
iv) Clustered Systems
Like multiprocessor systems, but multiple systems working together
o Usually sharing storage via a storage-area network (SAN)
o 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
o Some clusters are for high-performance computing (HPC)
Applications must be written to use parallelization
o Some have distributed lock manager (DLM) to avoid conflicting operations
The following diagram shows clustered system
9. Evolution of Operating system
1. Serial processing
2. Simple Batch Processing
3. Multi programmed Batch Processing
4. Time-sharing
Simple Batch Systems
Improve the utilization of computers
Jobs are submitted on cards or tape to an operator who batches jobs together sequentially
Monitor – program that controls the execution of the jobs – simple OS
Job Control Language (JCL) – interface to the monitor
Hardware Features:
Memory Protection: do not allow the memory area containing the monitor to be
altered
Timer: prevents a job from monopolizing the system
Problems:
Bad utilization of CPU Time – the processor stays idle while I/O devices are in
use
Multiprogrammed Batch Systems
o More than one program resides in the main memory
o While a program A uses an I/O device, the processor does not stay idle,
instead it rums another program B
New Features:
Memory Management: - to have several jobs ready to run, they must be kept in
main memory
Job Scheduling : the processor must decide which program to run
Time-Sharing Systems
Multiprogramming Systems :
Several Programs use the Computer System
Time-Sharing systems :
Several (human) users use the computer system interactively
Characteristics:
Using multiprogramming to handle multiple interactive jobs
Processor’s time is shared among multiple users
Multiple users simultaneously access the system through terminals
10. 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:
o User interface - Almost all operating systems have a user interface (UI).
Varies between Command-Line (CLI), Graphics User Interface (GUI),
Batch
o 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)
o I/O operations - A running program may require I/O, which may involve a file
or an I/O device
o File-system manipulation- The file system is of particular interest. Programs
need to read and write files and directories, create and delete them, search them,
list file Information, permission management.
o Communications – Processes may exchange information, on the same computer
or between computers over a network
Communications may be via shared memory or through message passing
o Error detection – OS needs to be constantly aware of possible errors
May occur in the CPU and memory hardware, in I/O devices, in user
program
For each type of error, OS should take the appropriate action to ensure
correct and consistent computing
o Resource allocation - When multiple users or multiple jobs running
concurrently, resources must be allocated to each of them
Many types of resources - CPU cycles, main memory, file storage, I/O
devices.
o Accounting - To keep track of which users use how much and what kinds of
computer resources
o Protection and security - The owners of information stored in a multiuser or
networked computer system may want to control use of that information,
concurrent processes should not interfere with each other
Protection involves ensuring that all access to system resources is
controlled
Security of the system from outsiders requires user authentication,
extends to defending external I/O devices from invalid access attempts
View of Operating System Services
11. System calls
Programming interface to the services provided by the OS
Typically written in a high-level language (C or C++)
Mostly accessed by programs via a high-level Application Programming Interface
(API) rather than direct system call use
Three most common APIs
a. Win32 API for Windows
b. POSIX API - UNIX, Linux, and Mac OS X)
c. Java API for the Java virtual machine (JVM)
System Call Implementation
Typically, a number associated with each system call
o System-call interface maintains a table indexed according to these
numbers
The system call interface invokes the intended system call in OS kernel and
returns status of the system call and any return values
API – System Call – OS Relationship
System Call Parameter Passing
Three general methods used to pass parameters to the OS
o Simplest: pass the parameters in registers
In some cases, may be more parameters than registers
o Parameters stored in a block, or table, in memory, and address of block passed
as a parameter in a register
This approach taken by Linux and Solaris
o Parameters placed, or pushed, onto the stackby the program and poppedoff
the stack by the operating system
Parameter Passing via Table
Types of System Calls
Process control
o create process, terminate process
o end, abort
o load, execute
o get process attributes, set process attributes
o wait for time
o wait event, signal event
o allocate and free memory
Example: fork(),exit(),wait()
File management
o create file, delete file
o open, close file
o read, write, reposition
o get and set file attributes
Example: open(),read(),write(),close()
Device management
o request device, release device
o read, write, reposition
o get device attributes, set device attributes
o logically attach or detach devices
Example: ioctl(), read(), write()
Information maintenance
o get time or date, set time or date
o get system data, set system data
o get and set process, file, or device attributes
Example: getpid(), sleep(), alarm()
Communications
o create, delete communication connection
o send, receive messages
message passing and shared memory
o transfer status information
o attach and detach remote devices
Example:pipe(), shmget(), mmap()
Protection
o Control access to resources
o Get and set permissions
o Allow and deny user access
Example: chmod(),umask(),chown()
Standard C Library Example
C program invoking printf() library call, which calls write() system call
System Programs
System programs provide a convenient environment for program development and
execution. They can be divided into:
o File manipulation
o Create, delete, copy, rename, print, dump, list, and generally manipulate files
and directories
o Status information
o date, time, amount of available memory, disk space, number of users
o Others provide detailed performance, logging, and debugging information
o File modification
o Text editors to create and modify files
o Programming language support
o Compilers, assemblers, debuggers and interpreters sometimes provided
o Program loading and execution
o Loaders, Linkers
o Communications
o Provide the mechanism for creating virtual connections among processes,
users, and computer systems
o Allow users to send messages to one another’s screens, browse web pages,
send electronic-mail messages, log in remotely, transfer files from one
machine to another
o Background services
o Launch at boot time
o Some for system startup, then terminate
o Some from system boot to shutdown
o Provide facilities like disk checking, process scheduling, error logging,
printing
o Application programs
o Run by users
o Launched by command line, mouse click, finger poke
12. Operating System Structure
Two Goals
a. User goals – operating system should be convenient to use, easy to learn, reliable,
safe, and fast
b. System goals – operating system should be easy to design, implement, and
maintain, as well as flexible, reliable, error-free, and efficient
Various ways to structure ones
1. Simple structure – MS-DOS
2. More complex -- UNIX
3. Layered – an abstrcation
4. Microkernel -Mach
1. Simple Structure -- MS-DOS
MS-DOS – written to provide the most functionality in the least space
o Not divided into modules
o its interfaces and levels of functionality are not well separated
Simple Structure -- MS-DOS
2. Simple Structure -- UNIX
UNIX – limited by hardware functionality
The UNIX OS consists of two separable parts
o Systems programs
o The kernel
Consists of everything below the system-call interface and above
the physical hardware
Provides the file system, CPU scheduling, memory management,
and other operating-system functions; a large number of functions
for one level
Traditional UNIX System Structure
3. 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
Layered Approach
4. Microkernel System Structure
o Moves as much from the kernel into user space
o Mach example of microkernel
Mac OS X kernel (Darwin) partly based on Mach
o Communication takes place between user modules using message passing
o Benefits:
Easier to extend a microkernel
Easier to port the operating system to new architectures
More reliable (less code is running in kernel mode)
More secure
Microkernel System Structure
5. Solaris Modular Approach
Many modern operating systems implement loadablekernel modules
o Uses object-oriented approach
o Each core component is separate
o Each talks to the others over known interfaces
o Each is loadable as needed within the kernel
Overall, similar to layers but with more flexible
o Linux, Solaris, etc
Solaris Modular Approach
6. Hybrid Systems
Most modern operating systems are actually not one pure model
o Hybrid combines multiple approaches to address performance, security,
usability needs
o Linux and Solaris - monolithic, plus modular for dynamic loading of
functionality
o Windows - monolithic, plus microkernel for different subsystem
personalities
Apple Mac OS X hybrid, layered, Aqua UI plus Cocoa programming
environment
o Below is kernel consisting of Mach microkernel and BSD Unix parts, plus
I/O kit and dynamically loadable modules (called kernel extensions)
Mac OS X Structure
7. iOS
Apple mobile OS for iPhone, iPad
o Structured on Mac OS X, added functionality
o Cocoa Touch Objective-C API for developing apps
o Media services layer for graphics, audio, video
o Core services provides cloud computing, databases
o Core operating system, based on Mac OS X kernel
iOS
8. Android
Developed by Open Handset Alliance (mostly Google)
o Open Source
Similar stack to iOS
Based on Linux kernel but modified
o Provides process, memory, device-driver management
o Adds power management
Runtime environment includes core set of libraries and Dalvik virtual machine
o Apps developed in Java plus Android API
Libraries include frameworks for
o web browser (webkit),
o database (SQLite),
o Multimedia and smaller libc
Android Architecture
[Link] System Generation
Operating systems are designed to run on any of a class of machines; the system must be
configured for each specific computer site
SYSGEN program obtains information concerning the specific configuration of the
hardware system
o Used to build system-specific compiled kernel or system-tuned
System Boot
When power initialized on system, execution starts at a fixed memory location
o Firmware ROM used to hold initial boot code
Operating system must be made available to hardware so hardware can start it
o Small piece of code – bootstrap loader, stored in ROM or EEPROM locates the
kernel, loads it into memory, and starts it
o Example : GRUB
15. Operating-System Operations
1. Process Management
A process is a program in execution.
o Program is a passive entity, process is an active entity.
Process needs resources to accomplish its task
o CPU, memory, I/O, files
o Initialization data
Single-threaded process has one program counter specifying location of next
instruction to execute
o Process executes instructions sequentially, one at a time, until completion
Multi-threaded process has one program counter per thread
Process Management Activities
Creating and deleting both user and system processes
Suspending and resuming processes
process synchronization
process communication
deadlock handling
2. 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
Memory management activities
o Keeping track of which parts of memory are currently being used and by
whom
o Deciding which processes (or parts thereof) and data to move into and out of
memory
o Allocating and deallocating memory space as needed
3. Storage Management
OS provides uniform, logical view of information storage
o Abstracts physical properties to logical storage unit - file
o Each medium is controlled by device (i.e., disk drive, tape drive)
properties include access speed, capacity, data-transfer rate, access
method (sequential or random)
4. File-System management
o Files usually organized into directories
o Access control on most systems to determine who can access what
OS activities
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
5. Mass-Storage Management
Usually disks used to store data that must be kept for a “long” period of time
OS activities
o Free-space management
o Storage allocation
o Disk scheduling
6. I/O Subsystem
One purpose of OS is to hide peculiarities of hardware devices from the user
I/O subsystem responsible for
o Memory management of I/O including
buffering (storing data temporarily while it is being transferred),
caching (storing parts of data in faster storage for performance),
spooling (the overlapping of output of one job with input of other jobs)
o General device-driver interface
o Drivers for specific hardware devices
7. 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