OS - Module 2 - Operating System Structure

Download as pdf or txt
Download as pdf or txt
You are on page 1of 75

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)

Operating System Structure 2


Operating Systems

OS Service Management

Operating System Structure 3


Operating Systems

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

Operating System Structure 4


Operating Systems

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

Operating System Structure 5


Operating Systems

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

Operating System Structure 6


Operating Systems

I/O System Management


• Operating system is responsible for I/O system management
• The I/O system consists of:
o A buffer-caching system
o A general device-driver interface
o Drivers for specific hardware devices

Operating System Structure 7


Operating Systems

Secondary Storage Management


• Since main memory (primary storage) is volatile and too small to
accommodate all data and programs permanently, the computer
system must provide secondary storage to back up main memory
• Most modern computer systems use disks as the principle on-line
storage medium, for both programs and data
• The operating system is responsible for the following activities in
connection with disk management:
o Free space management
o Storage allocation
o Disk scheduling

Operating System Structure 8


Operating Systems

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

Operating System Structure 9


Operating Systems

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

Operating System Structure 10


Operating Systems

Operating System Services

Operating System Structure 11


Operating Systems

Operating System Services


• Operating systems provide an environment for execution of programs
and services to programs and users
• A set of operating system services provides functions that are helpful
to the user
• User interface
o Almost all operating systems have a user interface (UI)
▪ Varies between Command-Line (CLI), Graphics User Interface (GUI), Batch
• Program execution
o The system must be able to load a program into memory and to run that
program, end execution, either normally or abnormally (indicating error)

Operating System Structure 12


Operating Systems

Operating System Services


• I/O operations
o since user programs cannot execute I/O operations directly, the operating
system must provide some means to perform I/O
• File-system manipulation
o Programs need to read and write files and directories, create and delete
them, search them, list file Information, permission management
o Operating system helps the programs to achieve that

Operating System Structure 13


Operating Systems

Operating System Services


• Communications
o Processes may exchange information, on the same computer or between
computers over a network
o Communications may be via shared memory or through message passing
(packets moved by the OS)
• Error detection
o 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
▪ Debugging facilities can greatly enhance the user’s and programmer’s abilities to
efficiently use the system

Operating System Structure 14


Operating Systems

Operating System Services


• Resource allocation
o When multiple users or multiple jobs running concurrently, resources must
be allocated to each of them
▪ Many types of resources - Some (such as CPU cycles, main memory, and file storage)
may have special allocation code, others (such as I/O devices) may have general request
and release code
• Accounting
o To keep track of which users use how much and what kinds of computer
resources

Operating System Structure 15


Operating Systems

Operating System Services


• Protection and security
o 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
o Protection
▪ involves ensuring that all access to system resources is controlled
o Security
▪ of the system from outsiders requires user authentication, extends to defending external
I/O devices from invalid access attempts
• If a system is to be protected and secure, precautions must be instituted throughout it. A
chain is only as strong as its weakest link

Operating System Structure 16


Operating Systems

A View of Operating System Services

Operating System Structure 17


Operating Systems

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

Operating System Structure 19


Operating Systems

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

Operating System Structure 20


Operating Systems

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 Structure 21


Operating Systems

Operating System
Design and Implementation

Operating System Structure 22


Operating Systems

Operating System Design and Implementation


• Design and Implementation of OS not “solvable”, but some
approaches have proven successful
• Internal structure of different Operating Systems can vary widely
• Start by defining goals and specifications
• Affected by choice of hardware, type of system
• User goals and System goals

Operating System Structure 23


IT Service
Operating
Management
Systems

OS Design Goals

User goals System goals


• Operating system should be • Operating system should be
• convenient to use • easy to design
• easy to learn • implement
• reliable • maintain
• safe • flexible
• fast • reliable
• error-free
• efficient

Operating System Structure 24


Operating Systems

Operating System Design and Implementation


• Important principle to separate
o Policy: What will be done?
o Mechanism: How to do it?

• Mechanisms determine how to do something, policies decide what


will be done
o The separation of policy from mechanism is a very important principle, it
allows maximum flexibility if policy decisions are to be changed later
• Specifying and designing OS is highly creative task of software
engineering

Operating System Structure 25


Operating Systems

Operating System Implementation


• Much variation
o Early OSes in assembly language
o Then system programming languages like Algol, PL/1
o Now C, C++
• Actually usually a mix of languages
o Lowest levels in assembly
o Main body in C
o Systems programs in C, C++, scripting languages like PERL, Python, shell scripts
• Code written in a high-level language:
o can be written faster
o is more compact
o is easier to understand and debug
• An operating system is far easier to port (move to some other hardware) if
it is written in a high-level language

Operating System Structure 26


Operating Systems

Operating System Debugging


• Debugging is finding and fixing errors, or bugs
• OS generates log files containing error information
• Core Dump
o Failure of an application can generate core dump file capturing memory of the
process
• Crash Dump
o Operating system failure can generate crash dump file containing kernel memory
• Beyond crashes, performance tuning can optimize system performance
o Sometimes using trace listings of activities, recorded for analysis
o Profiling is periodic sampling of instruction pointer to look for statistical trends

Operating System Structure 27


Operating Systems

Operating System Generation (SYSGEN)


• Operating systems are designed to run on any of a class of machines
o 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
o Can generate more efficient code than one general kernel

Operating System Structure 28


Operating Systems

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

Operating System Structure 30


Operating Systems

Command Line Interpreter (CLI)


• CLI or command interpreter allows direct command entry
• Sometimes implemented in kernel, sometimes by systems program
• Sometimes multiple flavors implemented – shells
• Primarily fetches a command from user and executes it
o Sometimes commands built-in, sometimes just names of programs
▪ If the latter, adding new features doesn’t require shell modification

Operating System Structure 31


Operating Systems

Bourne Shell Command Interpreter

Operating System Structure 32


Operating Systems

Graphical User Interface (GUI)


• User-friendly desktop metaphor interface
o Usually mouse, keyboard, and monitor
o Icons represent files, programs, actions, etc
o Various mouse buttons over objects in the interface cause various actions
(provide information, options, execute function, open directory (known as a
folder)
o Invented at Xerox PARC

• Many systems now include both CLI and GUI interfaces


o Microsoft Windows is GUI with CLI “command” shell
o Apple Mac OS X is “Aqua” GUI interface with UNIX kernel underneath and
shells available
o Unix and Linux have CLI with optional GUI interfaces (CDE, KDE, GNOME)

Operating System Structure 33


Operating Systems

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

Operating System Structure 34


Operating Systems

Operating System Structure

Operating System Structure 35


Operating Systems

Operating System Structure


• General-purpose OS is very large program
• Various ways to structure one as follows

Operating System Structure 36


Operating Systems

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

Operating System Structure 37


Operating Systems

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

• With modularity, layers are selected such


that each uses functions (operations) and
services of only lower-level layers

Operating System Structure 38


Operating Systems

An Operating System Layer

Operating System Structure 39


Operating Systems

OS/2 Layer Structure

Operating System Structure 40


Operating Systems

Kernel & Kernel Mode


• Kernel is part of operating system that includes most heavily used functions
• Generally, kernel is permanently in main memory
• Kernel Mode
o It is a privileged, nucleus or supervisory mode into which the machine switches when
the OS is running
o Enables the execution of such privileged instructions
▪ Such as in the area of I/O operations, which are not available to user mode
• The techniques by which a user program requests the kernel’s services are;
o System calls
o Message passing

• The process can only be switched into kernel mode by the above actions

Operating System Structure 41


Operating Systems

Kernel & Kernel Mode


• No other way that a user program can execute kernel instructions
• This facility is not given to user program in order to enforce system
security

User process
User space

Supervisor process Supervisor


space

Supervisor & user memory

Operating System Structure 42


Operating Systems

Monolithic Structure – Original UNIX


• UNIX – limited by hardware functionality, the original UNIX operating
system had limited structuring
• 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

Operating System Structure 43


Operating Systems

Traditional UNIX System Structure


Beyond simple but not fully layered

Operating System Structure 44


Operating Systems

Microkernel System Structure


• Moves as much from the kernel into user space
• Mach example of microkernel
o Mac OS X kernel (Darwin) partly based on Mach
• Communication takes place between user modules using message
passing
• Benefits:
o Easier to extend a microkernel
o Easier to port the operating system to new architectures
o More reliable (less code is running in kernel mode)
o More secure
• Detriments:
o Performance overhead of user space to kernel space communication
Operating System Structure 45
Operating Systems

Microkernel System Structure

Application File Device user


Program System Driver mode

messages messages

Interprocess memory CPU kernel


Communication managment scheduling mode

microkernel

hardware

Operating System Structure 46


Operating Systems

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

• Overall, similar to layers but with more flexible


o Linux, Solaris, etc

Operating System Structure 47


Operating Systems

Linux System Structure


• Monolithic plus modular design

Operating System Structure 48


Operating Systems

Solaris Modular Approach

Operating System Structure 49


Operating Systems

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)

Operating System Structure 50


Operating Systems

Mac OS X Structure
graphical user interface
Aqua

application environments and services

Java Cocoa Quicktime BSD

kernel environment
BSD

Mach

I/O kit kernel extensions

Operating System Structure 51


Operating Systems

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

Operating System Structure 52


Operating Systems

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

Operating System Structure 53


Operating Systems

Android Architecture Applications

Application Framework

Libraries Android runtime

SQLite openGL Core Libraries

surface media
Dalvik
manager framework
virtual machine
webkit libc

Operating System Structure


Linux kernel
54
Operating Systems

System Calls

Operating System Structure 55


Operating Systems

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)

Operating System Structure 56


Operating Systems

System Calls Example


• Compilation Process
o To compile a program, a process calls the command interpreter or shell, reads
command from the terminal
o Shell will create a new process to compile the program
o When the process has completed compilation, it executes a system call to
terminate itself
• Other process system calls are also available to;
o Request for more memory
o Released unused/extra memory
o Process and memory management

Operating System Structure 57


Operating Systems

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)

• MS-DOS uses software interrupts similar to system calls


Operating System Structure 58
Operating Systems

System Call Implementation


• Typically, a number is 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
• The caller need know nothing about how the system call is
implemented
o Just needs to obey API and understand what OS will do as a result call
o Most details of OS interface hidden from programmer by API
▪ Managed by run-time support library (set of functions built into libraries included with
compiler)

Operating System Structure 59


Operating Systems

API – System Call – OS Relationship

Operating System Structure 60


Operating Systems

System Call Processing


• Three general methods are used to pass parameters between a
running program and the operating system
o Pass parameters in registers
o Store the parameters in a table in memory, and the table address is passed as
a parameter in a register
o Push (store) the parameters onto the stack by the program, and pop off the
stack by operating system

Operating System Structure 61


Operating Systems

System Call Processing

Parameter Passing via Table


Operating System Structure 62
Operating Systems

Types of System Calls


• Process control
• File management
• Device management
• Information maintenance
• Communications

Operating System Structure 63


Operating Systems

Types of System Calls


• Process control
o end, abort
o load, execute
o create process, terminate process
o get process attributes, set process attributes
o wait for time
o wait event, signal event
o allocate and free memory

o Dump memory if error


o Debugger for determining bugs, single step execution
o Locks for managing access to shared data between processes

Operating System Structure 64


Operating Systems

Types of System Calls


• File management
o create file, delete file
o open, close file
o read, write, reposition
o get and set file attributes

• Device management
o request device, release device
o read, write, reposition
o get device attributes, set device attributes
o logically attach or detach devices

Operating System Structure 65


Operating Systems

Types of System Calls


• 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

• 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

Operating System Structure 66


Operating Systems

Types of System Calls


• Protection
o Control access to resources
o Get and set permissions
o Allow and deny user access

Operating System Structure 67


Operating Systems

Examples of Windows and Unix System Calls

Operating System Structure 68


Operating Systems

Standard C Library Example

C program invoking printf() library call, which calls write() system call
Operating System Structure 69
Operating Systems

Interrupts

Operating System Structure 70


Operating Systems

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

Operating System Structure 71


Operating Systems

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

Operating System Structure 72


Operating Systems

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

Operating System Structure 73


Operating Systems

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

Operating System Structure 74


Operating Systems

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

Operating System Structure 75

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy