Upload
clementine-shaw
View
212
Download
0
Embed Size (px)
Citation preview
2.1 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
Chapter 2: Operating-System Structures
2.2 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
Standard C Library Example
C program invoking printf() library call, which calls write() system call
2.3 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
System Call Parameter Passing
Often, more information is required than simply identity of desired system call Exact type and amount of information vary according to OS and
call
Three general methods used to pass parameters to the OS Simplest: pass the parameters in registers
In some cases, may be more parameters than registers 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
Parameters placed, or pushed, onto the stack by the program and popped off the stack by the operating system
Block and stack methods do not limit the number or length of parameters being passed
2.4 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
Parameter Passing via Table
2.5 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
Types of System Calls
Process control
File management
Device management
Information maintenance
Communications
Protection
2.6 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
Examples of Windows and Unix System Calls
2.7 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
Process Control Issues
Loading and executing a programWhat happens to the existing program?
LostSuspended (saved and allowed to
continue later)Run concurrently (needs creation of new
process) Control execution of the new program (set
priority, set max execution time, terminate)
2.8 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
Process Control Issues (Contd.)
Waiting for jobs
wait time, wait event and signal event
Managing shared data
acquire lock, release lock, etc.
Handling termination process (Normal or abnormal)
Taking memory dump
Return control to calling process
2.9 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
MS-DOS execution
(a) At system startup (b) running a program
2.10 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
FreeBSD Running Multiple Programs
2.11 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
File Management Issues
Creating files and directories
Deleting files and directories
Read and write
Reposition
Set attributes and get attributes
Move and copy
Some OSes provide explicit system calls
Others provide API which is implemented using other system calls
2.12 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
Device Management Issues
Physical and virtual resources
Request and release devices in multi-user OS
Needed to ensure exclusive access to devices
Unmanaged access can lead to device contention and deadlocks
Read, write, reposition
Unix treats devices as files
2.13 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
Information Management Issues
Transferring information between OS and user programs
System time, date, information about users, processes, resources etc.
Tracing and debugging programs
Dumping, trace, etc.
Single step
Profiling of programs
Get and set of attributes of processes
2.14 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
Communication Issues
Message passing model
exchange between processes on same machine or different machine
Needs opening of a connection
Host name and process id
Open, close, accept connections
Daemon processes – waiting on incoming connections
2.15 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
Shared Memory
Shared memory create
Shared memory attach
Process inform OS that they want to remove the OS placed restriction about accessing each others memory
Modalities of data sharing determined by the processes and not the OS
2.16 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
System Programs
System programs provide a convenient environment for program development and execution. The can be divided into:
File manipulation
Status information
File modification
Programming language support
Program loading and execution
Communications
Application programs
Most users’ view of the operation system is defined by system programs, not the actual system calls
2.17 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
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
File management - Create, delete, copy, rename, print, dump, list, and generally manipulate files and directories
Status information
Some ask the system for info - date, time, amount of available memory, disk space, number of users
Others provide detailed performance, logging, and debugging information
Typically, these programs format and print the output to the terminal or other output devices
Some systems implement a registry - used to store and retrieve configuration information
2.18 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
System Programs (Cont.)
File modification Text editors to create and modify files Special commands to search contents of files or perform
transformations of the text Programming-language support - Compilers, assemblers, debuggers
and interpreters sometimes provided Program loading and execution- Absolute loaders, relocatable loaders,
linkage editors, and overlay-loaders, debugging systems for higher-level and machine language
Communications - 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
2.19 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
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
User goals and System goals User goals - Should be convenient to use, easy to learn,
reliable, safe, and fast
System goals - Should be easy to design, implement, and maintain, as well as flexible, reliable, error-free, and efficient
Affected by choice of hardware, type of system
2.20 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
Mechanism – Policy Separation
Policy: What will be done? Mechanism: How to do it? Examples
Class attendance credit – card scanner/signup sheet/roll call
Time-multiplexing of CPU – Timer constructLRU – Linked list implementation
The separation of policy from allows maximum flexibility if policy decisions are to be changed laterSolaris Scheduler
2.21 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
OS Implementation
Early OSes were written in assembly language Currently most OSes are written in C Advantages of using high-level language
Faster, compactEasier to understand, debug and take advantage of
compiler optimizationsPortable – MS DOS Vs. Unix
Possible disadvantage?Performance
2.22 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
OS Structure
Describes how the code of the OS is organized
Function call, information flow, etc.
Not enough thought on structure in early OSes
Heavy price - crashes, vulnerabilities, etc.
MS-DOS – written to provide the most functionality in the least space
Not divided into modules
Although MS-DOS has some structure, its interfaces and levels of functionality are not well separated
2.23 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
MS-DOS Layer Structure
2.24 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
OS Structures (Contd.)
Monolithic Kernel
Layered Structure
Micro-Kernel
Modular Approach
2.25 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
Monolithic Kernel
Approach followed by early UNIX
Kernel and system programs
Kernel is a collection of various sub-systems
File system
CPU Scheduling
Memory management
Communications
Very hard to maintain
Especially modifying or adding new functionality
2.26 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
Traditional UNIX System Structure
2.27 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
Layered Approach OS built as a set of layers
Bottom most layer is hardwareTop most layer is user interface
Each layer can invoke functionalities from layer immediately below it
AdvantagesEasy debugging Information hidingCode modifications are relatively simple
DrawbacksPlacing routines in layersLess efficient – too many calls across layers and too
much data passing
2.28 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
Layered Operating System
2.29 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
Microkernel System Structure
Mach OS by CMU to address problems with monolithic kernel
Moves as much from the kernel into “user” space Communication takes place between user modules
using message 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 space communication
2.30 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
Modules
Modern OSes implement kernel modulesUses object-oriented approach
Each core component is separate
Each talks to the others over known interfaces
Each is loadable as needed within the kernel
Features can be implemented dynamically
Overall, similar to layers but with more flexibility
2.31 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
Solaris Modular Approach
2.32 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
Hybrid Structure of Mac OS X
2.33 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
Virtual Machines
VM technology takes layered approach to its logical conclusion
Pioneered by IBM CP/CMS in 1967 Abstracts hardware resources into several
different executing environmentEach environment will be a separate machine
A VM provides an interface identical to the underlying bare hardware
Guest process is an OS The operating system creates the illusion that it
has its own processor and (virtual memory).
2.34 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
Virtual Machines (Cont.)
(a) Nonvirtual machine (b) virtual machine
2.35 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
Virtual Machines Benefits
Physical machine protected from VMs and VMs protected from one anotherVirus in a guest OS will not affect the host OS
VMS can share files (through file system volume)
VMs can also communicate (via virtual network interfaces)
Aids in development and testing of OSEliminates system development time
Cloud computing and economies of scaleResource optimization through consolidation
2.36 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
Virtual Machines Implementation
Difficult to produce exact duplicate of the underlying machine
VM software can run in kernel mode. The VMs should execute only in user mode
Guest OSes also have user and kernel modes Virtual user mode – virtual kernel mode
transitionsSystem calls cause transfer to VM monitorVM monitor changes the register contents
and program counter and transfer control back to guest OS
VMs can be slow VMs need some level of hardware support
2.37 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
Operating-System Debugging
Debugging is finding and fixing errors, or bugs.
OSes generate log files containing error information.
Failure of an application can generate core dump file capturing memory of the process.
Operating system failure can generate crash dump file containing kernel memory.
Beyond crashes, performance tuning can optimize system performance.
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.”
DTrace tool in Solaris, FreeBSD, Mac OS X allows live instrumentation on production systems.
Probes fire when code is executed, capturing state data and sending it to consumers of those probes.
2.38 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition
End of Chapter 2