ch2_OSStructures
-
Upload
abid-ur-rehman -
Category
Documents
-
view
224 -
download
0
Transcript of ch2_OSStructures
-
8/12/2019 ch2_OSStructures
1/54
Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition Modified by Dr Alvi
Chapter 2: Operating-SystemStructures
-
8/12/2019 ch2_OSStructures
2/54
2.2 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Chapter 2: Operating-System Structures
Operating System Services
User Operating System Interface
System Calls
Types of System Calls
System Programs
Operating System Design and ImplementationOperating System Structure
Operating System Debugging
Operating System Generation
System Boot
-
8/12/2019 ch2_OSStructures
3/54
2.3 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Objectives
To describe the services an operating system provides tousers, processes, and other systems
To discuss the various ways of structuring an operatingsystem
To explain how operating systems are installed andcustomized and how they boot
-
8/12/2019 ch2_OSStructures
4/54
2.4 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Operating System Services
Operating systems provide an environment for execution of programs
and services to programs and usersOne set of operating-system services provides functions that arehelpful to the user:
User interface - Almost all operating systems have a userinterface ( UI).
Varies between Command-Line (CLI), Graphics UserInterface (GUI), Batch, Gesture-based
Program execution - The system must be able to load aprogram into memory and to run that program, end execution,either normally or abnormally (indicating error)
I/O operations - A running program may require I/O, which mayinvolve a file or an I/O device
-
8/12/2019 ch2_OSStructures
5/54
2.5 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Operating System Services (Cont.)
One set of operating-system services provides functions that are helpful tothe user (Cont.):
File-system manipulation - The file system is of particular interest.Programs need to read and write files and directories, create and deletethem, search them, list file Information, permission management.
Communications Processes may exchange information, on the samecomputer or between computers over a network
Communications may be via shared memory or through messagepassing (packets moved by the OS)
Error detection OS needs to be constantly aware of possible errors
May occur in the CPU and memory hardware, in I/O devices, in userprogram
For each type of error, OS should take the appropriate action toensure correct and consistent computing
Debugging facilities can greatly enhance the user
s andprogrammer
s abilities to efficiently use the system
-
8/12/2019 ch2_OSStructures
6/54
-
8/12/2019 ch2_OSStructures
7/542.7 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
A View of Operating System Services
-
8/12/2019 ch2_OSStructures
8/542.8 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
User Operating System Interface - CLI
CLI or command interpreter allows direct command entry
Sometimes implemented in kernel, sometimes by systemsprogram
Sometimes multiple flavors implemented shells
Primarily fetches a command from user and executes it
Sometimes commands built-in, sometimes just names ofprograms
If the latter, adding new features doesn t require shellmodification
-
8/12/2019 ch2_OSStructures
9/542.9 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Bourne Shell Command Interpreter
-
8/12/2019 ch2_OSStructures
10/542.10 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
User Operating System Interface - GUI
User-friendly desktop metaphor interface
Usually mouse, keyboard, and monitor
Icons represent files, programs, actions, etc
Various mouse buttons over objects in the interface causevarious actions (provide information, options, execute function,open directory (known as a folder )
Invented at Xerox PARC
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 availableUnix and Linux have CLI with optional GUI interfaces (CDE,KDE, GNOME)
-
8/12/2019 ch2_OSStructures
11/542.11 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Touchscreen Interfaces
Touchscreen devices require newinterfaces
Mouse not possible or not desired
Actions and selection based ongestures
Virtual keyboard for text entry
Voice commands.
-
8/12/2019 ch2_OSStructures
12/542.12 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
The Mac OS X GUI
-
8/12/2019 ch2_OSStructures
13/542.13 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
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-levelApplication Programming Interface (API) rather thandirect system call use Three most common APIs are Win32 API for Windows,POSIX API for POSIX-based systems (including virtuallyall versions of UNIX, Linux, and Mac OS X), and Java APIfor the Java virtual machine (JVM)
Note that the system-call names used throughout thistext are generic
-
8/12/2019 ch2_OSStructures
14/542.14 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Example of System Calls
System call sequence to copy the contents of one file to another file
-
8/12/2019 ch2_OSStructures
15/542.15 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Example of Standard API
-
8/12/2019 ch2_OSStructures
16/542.16 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
System Call Implementation
Typically, a number associated with each system call
System-call interface maintains a table indexed according tothese numbers
The system call interface invokes the intended system call in OSkernel and returns status of the system call and any return values
The caller need know nothing about how the system call isimplemented
Just needs to obey API and understand what OS will do as aresult call
Most details of OS interface hidden from programmer by API
Managed by run-time support library (set of functions builtinto libraries included with compiler)
-
8/12/2019 ch2_OSStructures
17/542.17 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
API System Call OS Relationship
-
8/12/2019 ch2_OSStructures
18/542.18 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
System Call Parameter Passing
Often, more information is required than simply identity of desiredsystem call
Exact type and amount of information vary according to OSand call
Three general methods used to pass parameters to the OSSimplest: pass the parameters in registers
In some cases, may be more parameters than registersParameters stored in a block , or table, in memory, andaddress of block passed as a parameter in a register
This approach taken by Linux and SolarisParameters placed, or pushed , onto the stack by the program
and popped off the stack by the operating systemBlock and stack methods do not limit the number or length ofparameters being passed
-
8/12/2019 ch2_OSStructures
19/54
-
8/12/2019 ch2_OSStructures
20/542.20 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Types of System Calls
Process control
create process, terminate processend, abort
load, execute
get process attributes, set process attributes
wait for timewait 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
-
8/12/2019 ch2_OSStructures
21/54
-
8/12/2019 ch2_OSStructures
22/542.22 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
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
Communications
create, delete communication connectionsend, receive messages if message passing model to hostname or process name
From client to server
Shared-memory model create and gain access to memoryregions
transfer status information
attach and detach remote devices
-
8/12/2019 ch2_OSStructures
23/542.23 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Types of System Calls (Cont.)
Protection
Control access to resources
Get and set permissions
Allow and deny user access
-
8/12/2019 ch2_OSStructures
24/54
2.24 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Examples of Windows and Unix System Calls
-
8/12/2019 ch2_OSStructures
25/54
2.25 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Standard C Library Example
C program invoking printf() library call, which calls write() system call
-
8/12/2019 ch2_OSStructures
26/54
2.26 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Example: MS-DOS
Single-tasking
Shell invoked when systembooted
Simple method to runprogram
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
-
8/12/2019 ch2_OSStructures
27/54
2.27 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Example: FreeBSD
Unix variant
MultitaskingUser login -> invoke user
s choice ofshell
Shell executes fork() system call to createprocess
Executes exec() to load program intoprocess
Shell waits for process to terminate orcontinues with user commands
Process exits with:
code = 0 no error code > 0 error code
-
8/12/2019 ch2_OSStructures
28/54
2.28 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
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
Most users
view of the operating system is defined by systemprograms, not the actual system calls
-
8/12/2019 ch2_OSStructures
29/54
2.29 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
System Programs
Provide a convenient environment for program development andexecution
Some of them are simply user interfaces to system calls; othersare considerably more complex
File management - Create, delete, copy, rename, print, dump, list,and generally manipulate files and directories
Status informationSome ask the system for info - date, time, amount of availablememory, disk space, number of usersOthers provide detailed performance, logging, and debugginginformation
Typically, these programs format and print the output to theterminal or other output devicesSome systems implement a registry - used to store andretrieve configuration information
-
8/12/2019 ch2_OSStructures
30/54
-
8/12/2019 ch2_OSStructures
31/54
2.31 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
System Programs (Cont.)
Background Services
Launch at boot timeSome for system startup, then terminateSome from system boot to shutdown
Provide facilities like disk checking, process scheduling, errorlogging, printing
Run in user context not kernel contextKnown as services , subsystems , daemons
Application programsDon t pertain to system
Run by usersNot typically considered part of OSLaunched by command line, mouse click, finger poke
-
8/12/2019 ch2_OSStructures
32/54
2.32 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Operating System Design and Implementation
Design and Implementation of OS not
solvable
, but some
approaches have proven successfulInternal structure of different Operating Systems can vary widely
Start the design by defining goals and specifications
Affected by choice of hardware, type of systemUser goals and System goals
User goals operating system should be convenient to use,easy to learn, reliable, safe, and fast
System goals operating system should be easy to design,implement, and maintain, as well as flexible, reliable, error-free,and efficient
-
8/12/2019 ch2_OSStructures
33/54
2.33 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Operating System Design and Implementation (Cont.)
Important principle to separate
Policy : What will be done? Mechanism : Ho w to do it?
The separation of policy from mechanism is a very importantprinciple, it allows maximum flexibility if policy decisions are tobe changed later (example timer)
Specifying and designing an OS is highly creative task ofsoftware engineering
-
8/12/2019 ch2_OSStructures
34/54
2.34 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Implementation
Much variation
Early OSes in assembly languageThen 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 slowerEmulation can allow an OS to run on non-native hardware
-
8/12/2019 ch2_OSStructures
35/54
2.35 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Operating System Structure
General-purpose OS is very large program
Various ways to structure onesSimple structure MS-DOS
More complex -- UNIX
Layered an abstrcation
Microkernel -- Mach
-
8/12/2019 ch2_OSStructures
36/54
2.36 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Simple Structure -- MS-DOS
MS-DOS written to provide themost functionality in the leastspace
Not divided into modules
Although MS-DOS has somestructure, its interfaces and
levels of functionality are notwell separated
-
8/12/2019 ch2_OSStructures
37/54
2.37 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Non Simple Structure -- UNIX
UNIX limited by hardware functionality, the original UNIX
operating system had limited structuring. The UNIX OSconsists of two separable parts
Systems programs
The kernel
Consists of everything below the system-call interface
and above the physical hardwareProvides the file system, CPU scheduling, memorymanagement, and other operating-system functions; alarge number of functions for one level
Disadvantage: Difficult to implement and maintain
Performance advantage: Very little overhead in systemcall interface or in communication within kernel
-
8/12/2019 ch2_OSStructures
38/54
2.38 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Traditional UNIX System Structure
Beyond simple but not fully layered
-
8/12/2019 ch2_OSStructures
39/54
2.39 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Layered Approach
The operating system is dividedinto a number of layers (levels),each built on top of lowerlayers. The bottom layer (layer0), is the hardware; the highest(layer N) is the user interface.
With modularity, layers areselected such that each usesfunctions (operations) andservices of only lower-levellayers
Implies simplicity ofconstruction and debugging(perform debugging one layerat a time)
-
8/12/2019 ch2_OSStructures
40/54
2.40 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Certain data structures, hardware and operations of lower layers hiddenfrom the layer above, that uses them onlyRequires careful planning of layers: difficult to have such layering
Less efficient: system calls take longer, as travel down many layers
Being out of favour recently as a design methodology
Layered Approach (Cont.)
-
8/12/2019 ch2_OSStructures
41/54
2.41 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Microkernel System Structure
Moves as much from the kernel into user space
Mach example of microkernelMac OS X kernel ( Darwin ) partly based on Mach
Communication takes place between user modules usingmessage passing
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
Detriments:Performance overhead of user space to kernel spacecommunication
-
8/12/2019 ch2_OSStructures
42/54
2.42 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Microkernel System Structure
ApplicationProgram
FileSystem
DeviceDriver
InterprocessCommunication
memorymanagment
CPUscheduling
messagesmessages
microkernel
hardware
user mode
kernelmode
-
8/12/2019 ch2_OSStructures
43/54
2.43 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Modules
Many modern operating systems implement loadable kernelmodules
Uses object-oriented approach
Each core component is separate
Each talks to the others over known interfaces
Each is loadable as needed within the kernelOverall, similar to layers but more flexible as any module cancall any other module
Linux, Solaris, etc
Like microkernel in that core functionality in small core, but is
more efficient than microkernel because no message passingneeded by modules to communicate
-
8/12/2019 ch2_OSStructures
44/54
2.44 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Solaris Modular Approach
-
8/12/2019 ch2_OSStructures
45/54
2.45 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
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, somonolithic, plus modular for dynamic loading of functionality
Windows mostly monolithic, plus microkernel for differentsubsystem personal i t ies
Will discuss three hybrid systems now: Mac OS X, iOS and Android
Apple Mac OS X hybrid, layered, Aqua UI plus Cocoa programming environment
Below is kernel consisting of Mach microkernel and BSD Unixparts, plus I/O kit and dynamically loadable modules (calledkernel extensions )
-
8/12/2019 ch2_OSStructures
46/54
iOS
-
8/12/2019 ch2_OSStructures
47/54
2.47 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
iOS
Apple mobile OS for iPhone , iPad
Structured on Mac OS X, added functionality
Does not run OS X applications natively
Also runs on different CPU architecture(ARM vs. Intel)
Cocoa Touch Objective-C API fordeveloping apps
Media services layer for graphics, audio,video
Core services provides support for cloudcomputing, databases
Core OS , based on Mac OS X kernel on theprevious slide
A d id
-
8/12/2019 ch2_OSStructures
48/54
2.48 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Android
Developed by Open Handset Alliance (mostly Google)
Open SourceRuns on a variety of mobile platforms
Similar stack to IOS
Based on Linux kernel but modified by Google
Provides process, memory, device-driver management
Adds power management
Runtime environment includes core set of libraries and Dalvikvirtual machine
Apps developed in Java plus Android API
Java class files compiled to Java bytecode then translatedto executable than runs in Dalvik VM
Libraries include frameworks for developing web browsers(webkit), database (SQLite), multimedia, smaller libc
-
8/12/2019 ch2_OSStructures
49/54
2.49 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Android Architecture
Application Framework
Android runtime
Core Libraries
Dalvikvirtual machine
Libraries
SQLite openGL
surfacemanager
webkit libc
mediaframework
O i S D b i
-
8/12/2019 ch2_OSStructures
50/54
2.50 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
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 capturingmemory of the process
Operating system failure can generate crash dump file containingkernel memory
Beyond crashes, performance tuning can optimize system performance
Sometimes using t race l is t ing s of activities, recorded for analysis
Profiling is periodic sampling of instruction pointer to look forstatistical trends
Kernighan
s Law:
Debugging is twice as hard as writing the code in thefirst place. Therefore, if you write the code as cleverly as possible, youare, by definition, not smart enough to debug it.
P f T i g
-
8/12/2019 ch2_OSStructures
51/54
2.51 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Performance Tuning
Improve performance by
removing bottlenecksOS must provide means ofcomputing and displayingmeasures of systembehaviour
For example,
top
programor Windows Task Manager
O ti S t G ti
-
8/12/2019 ch2_OSStructures
52/54
2.52 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
Operating System Generation
Operating systems are designed to run on any of a class of
machines; the system must be configured for each specificcomputer site
SYSGEN program obtains information concerning the specificconfiguration of the hardware system
Used to build system-specific compiled kernel or system-
tunedCan generate more efficient code than one general kernel
Typical information that is required:
The type and number of CPUs
How will the disk be formatted
How much memory is available
What devices are available
S t B t
-
8/12/2019 ch2_OSStructures
53/54
2.53 Silberschatz, Galvin and Gagne 2013Operating System Concepts 9 th Edition
System Boot
When power initialized on system, execution starts at a fixed
memory locationFirmware ROM used to hold initial boot code
Operating system must be made available to hardware so hardwarecan start it
Small piece of code bootstrap loader , stored in ROM or
EEPROM locates the kernel, loads it into memory, and starts itSometimes two-step process where boot block at fixedlocation loaded by ROM code, which loads bootstrap loaderfrom disk
Common bootstrap loader, GRUB , allows selection of kernel from
multiple disks, versions, kernel optionsKernel loads and system is then running
-
8/12/2019 ch2_OSStructures
54/54