Chapter 2: Operating-System Structures Silberschatz, Galvin and Gagne ©2013 – 2

advertisement
Chapter 2: Operating-System
Structures
Operating System Concepts Essentials – 2nd Edition
Silberschatz, Galvin and Gagne ©2013
Chapter 2: Operating-System Structures
 Operating System Services
 User Operating System Interface
 System Calls
 System Programs
 Operating System Design and Implementation
 Operating System Structure
 System Boot
Operating System Concepts Essentials – 2nd Edition
2.2
Silberschatz, Galvin and Gagne ©2013
Objectives
 Describe services that operating system provides
 Discuss various ways of structuring an OS
 Explain how operating systems are installed and
how they boot
Operating System Concepts Essentials – 2nd Edition
2.3
Silberschatz, Galvin and Gagne ©2013
Operating System Services
 Operating systems provide an environment for:

Execution of programs

Services to programs and users
 OS provides services for user:

User interface - Almost all operating systems
have a userinterface (UI).
Varies
between Command-Line (CLI),
Graphics User Interface (GUI), Batch
Operating System Concepts Essentials – 2nd Edition
2.4
Silberschatz, Galvin and Gagne ©2013
Operating System Services
 OS provides services for user (cont.):

Program execution –
 Load
a program into memory
 Run
that program
 End
execution, either normally or abnormally
Operating System Concepts Essentials – 2nd Edition
2.5
Silberschatz, Galvin and Gagne ©2013
Operating System Services
 OS provides services for user (cont.):

I/O operations - running program may
require I/O
 File
I/O
 Device
I/O
Operating System Concepts Essentials – 2nd Edition
2.6
Silberschatz, Galvin and Gagne ©2013
Operating System Services
 OS provides services for user (cont.):

File-system manipulation
 Read
and write files and directories
 Create
and delete
 Search
 List
file information, permission
Operating System Concepts Essentials – 2nd Edition
2.7
Silberschatz, Galvin and Gagne ©2013
Operating System Services
 OS provides services for user (cont.)

Communications – Processes may exchange information,
on same computer or between computers over a network
 Communications
may be via:
–
shared memory
–
message passing
Operating System Concepts Essentials – 2nd Edition
2.8
Silberschatz, Galvin and Gagne ©2013
Operating System Services
 OS provides services for user (cont.)

Error detection – OS constantly aware of possible
errors
 CPUs,
 OS
memory hardware, I/O devices, user program
should take the appropriate action
Operating System Concepts Essentials – 2nd Edition
2.9
Silberschatz, Galvin and Gagne ©2013
Operating System Services
 OS provides services for resource sharing

Resource allocation – to multiple concurrent users
and jobs
 CPU
cycles
 Main memory
 File storage
 I/O devices.
Operating System Concepts Essentials – 2nd Edition
2.10
Silberschatz, Galvin and Gagne ©2013
Operating System Services
 OS provides services for resource sharing

Accounting - keep track of computer resources

Protection and security - control use of information
and eliminate process interference
 Protection
- controlled access to system resources
 Security – defend from outsiders
Operating System Concepts Essentials – 2nd Edition
2.11
Silberschatz, Galvin and Gagne ©2013
A View of Operating System Services
Operating System Concepts Essentials – 2nd Edition
2.12
Silberschatz, Galvin and Gagne ©2013
User Operating System Interface - CLI
Command interpreter - direct command entry

Implemented in kernel or as systems program

Multiple flavors – shells

Fetches command from user and executes it

Commands can be built-in

Commands as names of programs
 Adding
new features doesn’t require shell modification
Operating System Concepts Essentials – 2nd Edition
2.13
Silberschatz, Galvin and Gagne ©2013
Bourne Shell Command Interpreter
Operating System Concepts Essentials – 2nd Edition
2.14
Silberschatz, Galvin and Gagne ©2013
User Operating System Interface - GUI
 User-friendly desktop metaphor interface

Usually mouse, keyboard, monitor

Icons represent files, programs, actions, etc.

Mouse buttons cause various actions

Invented at Xerox PARC
Operating System Concepts Essentials – 2nd Edition
2.15
Silberschatz, Galvin and Gagne ©2013
User Operating System Interface - GUI
 Many systems now include both CLI and GUI interfaces

Microsoft Windows is GUI with CLI “command” shell

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)
Operating System Concepts Essentials – 2nd Edition
2.16
Silberschatz, Galvin and Gagne ©2013
Touchscreen Interfaces
 Touchscreen devices require
new interfaces

Mouse not possible

Actions based on gestures

Virtual keyboard for text entry

Voice commands.
Operating System Concepts Essentials – 2nd Edition
2.17
Silberschatz, Galvin and Gagne ©2013
The Mac OS X GUI
Operating System Concepts Essentials – 2nd Edition
2.18
Silberschatz, Galvin and Gagne ©2013
System Calls
 Programming interface to services provided by OS
 Typically written in high-level language (e.g., C)
 Mostly accessed via high-level Application
Programming Interface (API)

Rather than direct system call use
 Three most common APIs:

Win32 API for Windows

POSIX API for POSIX-based systems (UNIX, Linux)

Java API for Java virtual machine (JVM)
Operating System Concepts Essentials – 2nd Edition
2.19
Silberschatz, Galvin and Gagne ©2013
Example of System Calls
 System calls to copy contents of one file to another
Operating System Concepts Essentials – 2nd Edition
2.20
Silberschatz, Galvin and Gagne ©2013
System Call Implementation
 Typically, number associated with system call

System-call interface maintains table indexed
accordingly

System call interface invokes the intended system call
in OS kernel,

Returns status of the system call and any return values
Operating System Concepts Essentials – 2nd Edition
2.21
Silberschatz, Galvin and Gagne ©2013
System Call Implementation
 Caller need not know system call’s implementation

Caller needs to obey API

Most details of OS interface hidden by API
 Managed
by run-time support library
Operating System Concepts Essentials – 2nd Edition
2.22
Silberschatz, Galvin and Gagne ©2013
API – System Call – OS Relationship
Operating System Concepts Essentials – 2nd Edition
2.23
Silberschatz, Galvin and Gagne ©2013
Types of System Calls
 Process control

create process, terminate process

end, abort

load, execute

get process attributes, set process attributes

wait for time

wait event, signal event

allocate and free memory

Dump memory if error

Debugger for determining bugs, single step execution

Locks for managing access to shared data between
processes
Operating System Concepts Essentials – 2nd Edition
2.24
Silberschatz, Galvin and Gagne ©2013
Types of System Calls
 File management

create file, delete file

open, close file

read, write, reposition

get and set file attributes
Operating System Concepts Essentials – 2nd Edition
2.25
Silberschatz, Galvin and Gagne ©2013
Types of System Calls
 Device management

request device, release device

read, write, reposition

get device attributes, set device attributes

logically attach or detach devices
Operating System Concepts Essentials – 2nd Edition
2.26
Silberschatz, Galvin and Gagne ©2013
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
Operating System Concepts Essentials – 2nd Edition
2.27
Silberschatz, Galvin and Gagne ©2013
Types of System Calls (Cont.)
 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
Operating System Concepts Essentials – 2nd Edition
2.28
Silberschatz, Galvin and Gagne ©2013
Types of System Calls (Cont.)
 Protection

Control access to resources

Get and set permissions

Allow and deny user access
Operating System Concepts Essentials – 2nd Edition
2.29
Silberschatz, Galvin and Gagne ©2013
Examples of Windows and Unix System Calls
Operating System Concepts Essentials – 2nd Edition
2.30
Silberschatz, Galvin and Gagne ©2013
Standard C Library Example
 C -> printf() library call -> write() system call
Operating System Concepts Essentials – 2nd Edition
2.31
Silberschatz, Galvin and Gagne ©2013
Example: MS-DOS
 Single-tasking
 Shell invoked on
system boot
 Simple method to run
program

No process created
 Single memory space
 Loads program into
memory, overwriting all
but the kernel
 Program exit -> shell
At system startup
running a program
reloaded
Operating System Concepts Essentials – 2nd Edition
2.32
Silberschatz, Galvin and Gagne ©2013
Example: FreeBSD
 Unix variant
 Multitasking
 User login -> invoke user’s
choice of shell
 Shell executes fork() to create
process

exec() to load program into
process

Shell waits for process to
terminate or continues with user
commands
Operating System Concepts Essentials – 2nd Edition
2.33
Silberschatz, Galvin and Gagne ©2013
System Programs
 System programs provide convenient environment
for program development and execution

File manipulation

Status information

Programming language support

Program loading and execution

Communication

Background services

Application programs
Operating System Concepts Essentials – 2nd Edition
2.34
Silberschatz, Galvin and Gagne ©2013
Example System Programs
 File management - Create, delete, copy, rename,
print, dump, list, and generally manipulate files
and directories
Operating System Concepts Essentials – 2nd Edition
2.35
Silberschatz, Galvin and Gagne ©2013
Example System Programs
 Status information

Ask OS for info - date, time, amount of available
memory, disk space, number of users

Provide detailed performance, logging, and
debugging info

Some systems implement a registry - used to
store and retrieve configuration information
Operating System Concepts Essentials – 2nd Edition
2.36
Silberschatz, Galvin and Gagne ©2013
Example System Programs
 File modification

Text editors to create and modify files

Special commands to search contents of files or
perform transformations of the text
Operating System Concepts Essentials – 2nd Edition
2.37
Silberschatz, Galvin and Gagne ©2013
Example System Programs
 Programming-language support –

Compilers

Assemblers

Debuggers

Interpreters
Operating System Concepts Essentials – 2nd Edition
2.38
Silberschatz, Galvin and Gagne ©2013
Example System Programs
 Program loading and execution
Loaders

Linkers

Debugging systems for higher-level and machine
language
Operating System Concepts Essentials – 2nd Edition
2.39
Silberschatz, Galvin and Gagne ©2013
Example System Programs
 Communications – Provide mechanism for
creating virtual connections among processes,
users, and computer systems

Send messages to screens, browse web pages,
send electronic-mail messages, log in remotely,
transfer files
Operating System Concepts Essentials – 2nd Edition
2.40
Silberschatz, Galvin and Gagne ©2013
Example System Programs
 Background Services

Launched at boot time
 Some
for system startup, then terminate
 Some from system boot to shutdown

Provide facilities like disk checking, process
scheduling, error logging, printing

Run in user context not kernel context

Known as services, subsystems, daemons
Operating System Concepts Essentials – 2nd Edition
2.41
Silberschatz, Galvin and Gagne ©2013
Example System Programs
 Application programs

Don’t pertain to system

Run by users

Not typically considered part of OS

Launched by command line, mouse click, finger poke
Operating System Concepts Essentials – 2nd Edition
2.42
Silberschatz, Galvin and Gagne ©2013
Operating System Design and Implementation
 Design and Implementation of OS not “solvable”

Some approaches have proven successful
 Internal structure of OS can vary
 Start by defining goals and specifications
Operating System Concepts Essentials – 2nd Edition
2.43
Silberschatz, Galvin and Gagne ©2013
Operating System Design and Implementation
 Affected by hardware choice, type of system
 User goals and System goals

User goals – operating system should be:
 convenient,

easy, reliable, safe, and fast
System goals – operating system should be:
 easy
to design, implement, and maintain,
 flexible,
reliable, error-free, and efficient
Operating System Concepts Essentials – 2nd Edition
2.44
Silberschatz, Galvin and Gagne ©2013
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
Operating System Concepts Essentials – 2nd Edition
2.45
Silberschatz, Galvin and Gagne ©2013
Implementation
 High-level language easier to port to other hardware

But slower
 Emulation allows OS to run on non-native hardware
Operating System Concepts Essentials – 2nd Edition
2.46
Silberschatz, Galvin and Gagne ©2013
Operating System Structure
 General-purpose OS is very large program
 Various ways to structure ones

Simple structure – MS-DOS

More complex -- UNIX

Layered – an abstrcation

Microkernel -Mach
Operating System Concepts Essentials – 2nd Edition
2.47
Silberschatz, Galvin and Gagne ©2013
Simple Structure -- MS-DOS
 Provide most functionality
in least space

Not divided into modules

Interfaces and levels of
functionality are not well
separated
Operating System Concepts Essentials – 2nd Edition
2.48
Silberschatz, Galvin and Gagne ©2013
Non Simple Structure -- UNIX
 UNIX –OS consists of two separable parts

Systems programs

Kernel
 Everything
below system-call interface and above
physical hardware
 Provides
file system, CPU scheduling, memory
management, and other operating-system
functions
–
Large number of functions for one level
Operating System Concepts Essentials – 2nd Edition
2.49
Silberschatz, Galvin and Gagne ©2013
Traditional UNIX System Structure
Operating System Concepts Essentials – 2nd Edition
2.50
Silberschatz, Galvin and Gagne ©2013
Layered Approach
 OS divided into layers
(levels), each built on top
of lower layers.

Bottom layer (layer 0), is
hardware

Highest (layer N) is user
interface.
 Layers only use services
of lower-level layers
Operating System Concepts Essentials – 2nd Edition
2.51
Silberschatz, Galvin and Gagne ©2013
Microkernel System Structure
 Moves much kernel into user space
 Mach example of microkernel

OS X kernel (Darwin) partly based on Mach
 Communication takes place between user modules
using message passing
Operating System Concepts Essentials – 2nd Edition
2.52
Silberschatz, Galvin and Gagne ©2013
Microkernel System Structure
 Benefits:

Easier to extend microkernel

Easier to port the operating system to different
architectures

More reliable (less code is running in kernel mode)

More secure
 Detriments:

Overhead of user to kernel space communications
Operating System Concepts Essentials – 2nd Edition
2.53
Silberschatz, Galvin and Gagne ©2013
Microkernel System Structure
Application
Program
File
System
messages
Interprocess
Communication
Device
Driver
user
mode
messages
memory
managment
CPU
scheduling
kernel
mode
microkernel
hardware
Operating System Concepts Essentials – 2nd Edition
2.54
Silberschatz, Galvin and Gagne ©2013
Modules
 Modern OS implement loadable kernel modules

Uses object-oriented approach

Each core component is separate

Each talks to others over known interfaces

Each is loadable as needed
 Overall, similar to layers but with more flexible

Linux, Solaris, etc
Operating System Concepts Essentials – 2nd Edition
2.55
Silberschatz, Galvin and Gagne ©2013
Solaris Modular Approach
Operating System Concepts Essentials – 2nd Edition
2.56
Silberschatz, Galvin and Gagne ©2013
Hybrid Systems
 Most modern OS are 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
Operating System Concepts Essentials – 2nd Edition
2.57
Silberschatz, Galvin and Gagne ©2013
Hybrid Systems
 Apple Mac OS X hybrid, layered, Aqua UI plus Cocoa
programming environment

Kernel consists of:
 Mach
 BSD
 I/O
microkernel
Unix parts
kit
 Dynamically
loadable modules (kernel extensions)
Operating System Concepts Essentials – 2nd Edition
2.58
Silberschatz, Galvin and Gagne ©2013
Mac OS X Structure
graphical user interface
Aqua
application environments and services
Java
Cocoa
Quicktime
BSD
kernel environment
BSD
Mach
I/O kit
Operating System Concepts Essentials – 2nd Edition
kernel extensions
2.59
Silberschatz, Galvin and Gagne ©2013
iOS
 Apple mobile OS for iPhone, iPad

Structured on Mac OS X, w/ added functionality

Does not run OS X applications natively
 Also
runs on different CPU architecture (ARM vs. Intel)
Operating System Concepts Essentials – 2nd Edition
2.60
Silberschatz, Galvin and Gagne ©2013
iOS
 Cocoa Touch Objective-C API for developing apps
 Media services layer for graphics, audio, video
 Core services provides cloud computing, databases
 Core operating system, based on Mac OS X kernel
Operating System Concepts Essentials – 2nd Edition
2.61
Silberschatz, Galvin and Gagne ©2013
Android
 Developed by Open Handset Alliance (mostly Google)

Open Source
 Similar stack to IOS
 Based on Linux kernel

Provides process, memory, device-driver management

Adds power management
Operating System Concepts Essentials – 2nd Edition
2.62
Silberschatz, Galvin and Gagne ©2013
Android
 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
Operating System Concepts Essentials – 2nd Edition
2.63
Silberschatz, Galvin and Gagne ©2013
Applications
Android
Architecture
Application Framework
Libraries
Android runtime
SQLite
openGL
surface
manager
media
framework
webkit
Core Libraries
Dalvik
virtual machine
libc
Linux kernel
Operating System Concepts Essentials – 2nd Edition
2.64
Silberschatz, Galvin and Gagne ©2013
Operating-System Debugging
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.”
Operating System Concepts Essentials – 2nd Edition
2.65
Silberschatz, Galvin and Gagne ©2013
System Boot
 When power initialized, execution starts at fixed memory
location

Firmware ROM used to hold boot code
 Operating system must be made available to hardware

Small piece of code – bootstrap loader, stored in ROM or
EEPROM: locates the kernel, loads it into memory, starts it

Sometimes two-step process where:
 boot
block at fixed location loaded by ROM code
 which
loads bootstrap loader from disk
Operating System Concepts Essentials – 2nd Edition
2.66
Silberschatz, Galvin and Gagne ©2013
System Boot
 Common bootstrap loader, GRUB, allows selection of
kernel from multiple disks, versions, kernel options
 Kernel loads and system is then running
Operating System Concepts Essentials – 2nd Edition
2.67
Silberschatz, Galvin and Gagne ©2013
Download