OS - Module 2 - Operating System Structure
OS - Module 2 - Operating System Structure
OS - Module 2 - Operating System Structure
Module 2
Operating Systems
Operating Systems
Module Outline
• Process Management
• Memory Management
• File Management
• I/O System Management
• Secondary Storage Management
• Networking
• System Protection
• Operating System Services
• OS Layered Approach
o OS/2 Layer Structure
• Virtual Machines
• System Design Goals
• Mechanisms and Policies
• Operating System Implementation
• System Generation (SYSGEN)
OS Service Management
Process Management
• A process is a program in execution
• A process needs certain resources, including CPU time, memory, files,
and I/O devices, to accomplish its task
• The operating system is responsible for the following activities in
connection with process manager
o Process creation and termination
o Process suspension and resumption
o Provision of mechanisms for:
▪ process synchronization
▪ process communication
Memory Management
• Memory is a large array of words or bytes, each with its own address
• It is a repository of quickly accessible data shared by the CPU and I/O
devices.
• Main memory is a volatile storage device
o It looses its contents in the case of system failure
• The operating system is responsible for the following activities in
connections with memory management:
o Keep track of which parts of memory are currently being used and by whom
o Decide which processes to load when memory space becomes available
o Allocate and deallocate memory space as needed
File Management
• A file is a collection of related information defined by its creator
• Commonly, files represent programs (both source and object forms)
and data
• The operating system is responsible for the following activities in
connections with file management:
o File creation and deletion
o Directory creation and deletion
o Support of primitives for manipulating files and directories
o Mapping files onto secondary storage
o File backup on stable (nonvolatile) storage media
Networked System
• A networking system is a collection of processors
• The processors in the system are connected through a
communication network
• Communication takes place using a protocol
• This system provides user access to various system resources
• Access to a shared resource allows:
o Computation speed-up
o Increased data availability
o Enhanced reliability
System Protection
• Protection refers to a mechanism for controlling access by programs,
processes, or users to both system and user resources
• The protection mechanism must:
o distinguish between authorized and unauthorized access
o specify the controls to be imposed
o provide a means of enforcement
System Programs
• System programs provide a convenient environment for program
development and execution
▪ Some of them are simply user interfaces to system calls; others are considerably more
complex
• They can be divided into:
o File manipulation
o Status information sometimes stored in a File modification
o Programming language support
o Program loading and execution
o Communications
o Background services
• Most users’ view of the operation system is defined by system
programs, not the actual system calls
Operating System Structure 18
Operating Systems
System Programs
• File management
o Create, delete, copy, rename, print, dump, list, and generally manipulate files
and directories
• Status information
o Some ask the system for info - date, time, amount of available memory, disk
space, number of users
o Others provide detailed performance, logging, and debugging information
o Typically, these programs format and print the output to the terminal or other
output devices
o Some systems implement a registry - used to store and retrieve configuration
information
System Programs
• File modification
o Text editors to create and modify files
o Special commands to search contents of files or perform transformations of
the text
• Programming-language support
o Compilers, assemblers, debuggers and interpreters sometimes provided
• Program loading and execution
o Absolute loaders, relocatable loaders, linkage editors, and overlay-loaders,
debugging systems for higher-level and machine language
System Programs
• Communications
o Provide the mechanism for creating virtual connections among processes,
users, and computer systems
▪ 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
• Background Services
o Launch at boot time
▪ Some for system startup, then terminate
▪ Some from system boot to shutdown
o Provide facilities like disk checking, process scheduling, error logging, printing
o Run in user context not kernel context
o Known as services, subsystems, daemons
Operating System
Design and Implementation
OS Design Goals
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 Sometimes two-step process where boot block at fixed location loaded by ROM
code, which loads bootstrap loader from disk
o 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
Operating System Structure 29
Operating Systems
OS User Interface
Touch-screen Interface
• Touch-screen devices require new interfaces
o Mouse not possible or not desired
o Actions and selection based on gestures
o Virtual keyboard for text entry
Simple Structure
• I.e. MS-DOS – written to provide the most
functionality in the least space
o Not divided into modules
o Although MS-DOS has some structure, its
interfaces and levels of functionality are not
well separated
OS Layered Approach
• The operating system is divided into a
number of layers (levels), each built on top
of lower layers
o The bottom-most layer (layer 0), is the
hardware
o The highest (layer N) is the user interface
• The process can only be switched into kernel mode by the above actions
User process
User space
messages messages
microkernel
hardware
Modules
• Most modern operating systems implement loadable kernel 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
Hybrid Systems
• Most modern operating systems actually not one pure model
o 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
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
graphical user interface
Aqua
kernel environment
BSD
Mach
iOS
• Apple mobile OS for iPhone, iPad
o Structured on Mac OS X, added functionality
o Does not run OS X applications natively
▪ Also runs on different CPU architecture (ARM vs. Intel)
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
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
▪ 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
Application Framework
surface media
Dalvik
manager framework
virtual machine
webkit libc
System Calls
System Calls
• User program communicate with OS and request its services by making
system calls
• Corresponding to each system call is a library procedure that user program
can call
• System calls provide the interface between a running program and the OS
• Typically written in a high-level language (C or C++)
• All instructions with the hardware are implemented by system calls
• Mostly accessed by programs via a high-level Application Programming
Interface (API) rather than direct system call use
o 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)
▪ Java API for the Java virtual machine (JVM)
System Calls
• System calls related to file systems
o System calls are needed to create, read, move and write a file
▪ A file should be opened before read it
▪ Similarly, after reading file must be closed which is done by system calls
o System calls are required to
▪ create and remove a directory
▪ manipulate file with in different directories
• System V Unix provides about 64 system calls e.g.
o create(name, amode)
o open(name, oflag, amode)
o close(fd)
• Device management
o request device, release device
o read, write, reposition
o get device attributes, set device attributes
o logically attach or detach devices
• Communications
o create, delete communication connection
o send, receive messages if message passing model to host name or process
name
▪ From client to server
o Shared-memory model create and gain access to memory regions
o transfer status information
o attach and detach remote devices
C program invoking printf() library call, which calls write() system call
Operating System Structure 69
Operating Systems
Interrupts
Interrupts
• Mechanism by which hardware like I/O devices, memory modules
may interrupt the normal processing of the processor
• Interrupts are generated by various agents to notify the OS of the
occurrence of some event
o such as completion of an I/O activity
• When an interrupt occurs, the execution flow of processor is diverted
into specific part of OS code which deals with the event – interrupt
handler
• Interrupts are used to permit several programs and I/O activities to
process independently and asynchronously
o Hence improve the processing speed
Interrupts
• Advantages
o It provides a low overheads means of gaining the attention of the CPU
o Interrupt Vector Table is a location near the bottom of memory contains the
address of interrupt services procedures of I/O devices
• As each instruction terminates, the processor may checks for the
occurrence of interrupts
o If an interrupt received, the actual program is temporarily suspended, and the
processor is diverted to interrupt handling routine
o When the interrupt is served, the execution will return to the interrupted
program
Interrupts
• Example:
o External devices like printer are much slower than the processor
o When processor is transferring data to the printer, the processor pause and
remain idle until the printer is reading data
o I/O modules will send an interrupt request signal to the processor to suspend
its current processing and send more data
Interrupt Processing
• Following events occurs in processor hardware and software due to
an I/O interrupt
o The device issue an interrupt signal to processor
o The processor finishes execution of current instruction, saves states of
interrupted process before responding to the interrupt
o The processor sends an acknowledgment signal to the device that issued the
interrupt and device remove its interrupt signal/flag
o Processor transfer control to the appropriate interrupt handler routine and it
starts processing interrupt
o When the interrupt id served, the state of interrupted process is restored
o Next process starts execution
Types of Interrupts
Interrupts may be generated by a number of sources, which are following
• I/O:
o Generated by I/O device controller, to signal normal completion of event or the occurrence of
an error or failure condition
• Time:
o Generated by an internal clock within the processor due to expiration of a process’s time
quantum or receipt of a signal from another processor on a multiprocessor system
• Hardware error:
o Generated by hardware faults such as power failure
• Program:
o Generated in a user program as a result of instruction execution, such as;
▪ Arithmetic overflow
▪ Divide by zero
▪ Attempt to execute an illegal machine instruction
▪ Reference outside a user allowed memory space