02-Operating System Structures
02-Operating System Structures
(02)
2
Operating System Services
3
Operating System Services
– Program execution - The system must be able to load a program
into memory and to run that program, end execution.
5
Operating System Services
– Accounting - To keep track of which users use how much
and what kinds of computer resources.
6
A View of Operating System Services
7
A System Calls
• System calls provide the interface between a running
program and the operating system.
8
Example of System Calls
• System call sequence to copy the contents of one file to another file.
9
System Call Implementation
• Typically, a number associated with each system call
– System-call interface maintains a table indexed according to these
numbers
• The caller need know nothing about how the system call is
implemented
– Just needs to obey API and understand what OS will do as a result call.
– Most details of OS interface hidden from programmer by API
10
API – System Call – OS Relationship
11
Standard C Library Example
• C program invoking printf() library call, which calls write() system call
12
How System Call Parameter Passing
Three general methods are used to pass parameters between a running
program and the operating system.
– Pass parameters in registers.
– Store the parameters in a table in memory, and the table address
is passed as a parameter in a register.
– Push (store) the parameters onto the stack by the program, and
popped off the stack by operating system.
• Block and stack methods do not limit the number or length of
parameters being passed.
13
Parameter Passing via Table
14
Types of System Calls
• Process control
– end, abort
– load, execute
– process, terminate process
– get process attributes, set process attributes
– wait for time
– wait event, signal event
– allocate and free memory
• File management
– create file, delete file
– open, close file
– read, write, reposition
15
– get and set file attributes
Types of System Calls
• Device management
– request device, release device
– read, write, reposition
– get device attributes, set device attributes
– logically attach or detach devices
• 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 connection
– send, receive messages
– transfer status information 16
– attach and detach remote devices
Examples of Windows and
Unix System Calls
17
System Programs
• System programs provide a convenient environment for
program development and execution.
• They 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 operating system is defined by system
programs, not the actual system calls. 18
System Programs
File manipulation
– 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
File modification
– Text editors to create and modify files
– Special commands to search contents of files or perform
transformations of the text
19
System Programs
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.
Application programs
operating systems are supplied with programs that are useful in solving
common problems or performing common operations such as application 20
programs ex. web browsers, database systems, compilers, games.
Operating System Design and Implementation
• Internal structure of different Operating Systems can vary widely.
21
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
22
Simple Structure - MS-DOS
■ 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
23
Non Simple Structure- UNIX
UNIX – limited by hardware functionality, the original
UNIX operating system had limited structuring. The UNIX
OS consists of two separable parts
● Systems programs
● 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
24
Traditional UNIX System Structure
Beyond simple but not fully layered
Layered Approach
messages messages
microkernel
hardware
28
Modules
■ Many modern operating systems implement loadable
kernel modules
● Uses object-oriented approach
● Each core component is separate
● Each talks to the others over known interfaces
● Each is loadable as needed within the kernel
■ Overall, similar to layers but with more flexible
● Linux, Solaris, etc
29
Solaris Modular Approach
30
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, 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
● Below is kernel consisting of Mach microkernel and Berkeley
Standard Distribution (BSD) Unix parts, plus I/O kit and
dynamically loadable modules (called kernel extensions) 31
Mac OS X Structure
kernel environment
BSD
Mach
Application Framework
surface media
Dalvik
manager framework
virtual machine
webkit libc
35
Virtual Machines
• A virtual machine takes the layered approach to its logical
conclusion. It treats hardware and the operating system kernel as
though they were all hardware.
• The operating system host creates the illusion that a process has
its own processor and (virtual memory).
37
Virtual Machines
• (a) Non virtual machine (b) virtual machine
38
The Java Virtual Machine
39
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
● Sometimes using trace listings of activities, recorded for analysis
● Profiling is periodic sampling of instruction pointer to look for statistical
trends
40
Performance Tuning
■ Improve performance by
removing bottlenecks
■ OS must provide means of
computing and displaying
measures of system behavior
■ For example, “top” program or
Windows Task Manager
41
DTrace
■ Example of following
XEventsQueued system call
move from libc library to kernel
and back 2.42
Dtrace (Cont.)
2.43
Operating System Generation
• Operating systems are designed to run on any of a class of
machines; the system must be configured for each specific
computer site
44
System Boot
• Operating system must be made available to hardware so
hardware can start it
– Small piece of code – bootstrap loader, locates the
kernel, loads it into memory, and starts it