OS Chapter 2 - 1 16 17
OS Chapter 2 - 1 16 17
Structures
Chapter 2: Operating System Structures
Operating System Services
User Operating System Interface
System Calls
Types of System Calls
System Programs
Operating System Design and Implementation
Operating System Structure
Operating System Debugging
Operating System Generation
System Boot
Objectives
Touchscreen devices
require new interfaces
Mouse not possible or not
desired
Actions and selection based
on gestures
Virtual keyboard for text
entry
Voice commands.
The Mac OS X GUI
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-
level Application Programming
Interface (API) rather than direct system
call use
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), and Java
API for the Java virtual machine (JVM)
Example of System Calls
System call sequence to copy the contents of
one file to another file
Example of Standard API
System Call Implementation
Typically, a number associated with each system
call
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
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. Managed by run-time support library
API – System Call – OS Relationship
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
File management
create file, delete file
open, close file
read, write, reposition
get and set file attributes
Device management
request device, release device
read, write, reposition
get device attributes, set device attributes
logically attach or detach devices
Types of System Calls
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 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
Types of System Calls
Protection
Control access to resources
Get and set permissions
Allow and deny user access
Examples of Windows and Unix System Calls
Standard C Library Example
C program invoking printf() library call, which
calls write() system call
Example: MS-DOS
Single-tasking
Shell invoked when
system booted
Simple method to run
program
No process
created
Single memory space
Loads program into
memory, overwriting
all but the kernel
At system startup running a program
Program exit -> shell
reloaded
Example: FreeBSD
Unix variant
Multitasking
User login -> invoke user’s choice
of shell
Shell executes fork() system call to
create process
Executes exec() to load program
into process
Shell waits for process to
terminate or continues with user
commands
Process exits with:
code = 0 – no error
code > 0 – error code
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
Application programs
Most users’ view of the operation system is defined by
system programs, not the actual system calls
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
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 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 the design by defining goals and specifications
Affected by choice of hardware, type of system
User 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
Operating System Design and Implementation
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
Disadvantages of Monolithic OS
It is massive:
It performs all basic OS functions and takes up in the
order of megabytes of code and data
It is undifferentiated:
It is coded in a non-modular way (traditionally)
although modern ones are much more layered.
It is intractable:
Altering any individual software component to adapt it
to changing requirements is difficult.
37
Monolithic Operating System
Application Application
Programs Programs
User Mode
Kernel Mode
System Services
Application Application
Programs Programs
User Mode
Kernel Mode
System Services
Process Schedule
Hardware
Easier to enhance
Each layer of code access lower level interface
42
Low-application performance Ex : UNIX
Microkernel System Structure
Moves as much from the kernel into user space
Mach example of microkernel
Mac OS X kernel (Darwin) partly based on Mach
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
Microkernel
Monolithic
Kernel
Microkernel System Structure
messages messages
microkernel
hardware
Micro-kernel
46
Microkernel/Client Server OS
User
Kernel
Microkernel
Send
Reply Hardware
Microkernel
Hardw are
49
Comparison: Monolithic and
Micro-kernel OS Design
The chief advantages of a MK-based OS:
Extensibility and its ability to enforce modularity
behind memory protection boundaries
A relative small kernel is more likely to be free of bugs
than one that is larger and complex.
The advantage of a monolithic OS:
Relative efficiency with which operations can be
invoked is high because even invocation to a
separate user-level address space on the same node
is more costly.
50
Modules
54
Mac OS X Structure
kernel environment
BSD
Mach
Open Source
Similar stack to IOS
Based on Linux kernel but modified
Provides process, memory, device-driver management
Adds power management
Runtime environment includes core set of libraries
and Dalvik virtual machine
Apps developed in Java plus Android API
Javaclass files compiled to Java bytecode then translated to
executable that runs in Dalvik VM
Application Framework
surface media
Dalvik
manager framework
virtual machine
webkit libc
Linux kernel
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 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
Operating-System Debugging