Chapter 2: Operating-System 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
Virtual Machines
Operating System Generation
System Boot
Objectives
To describe the services an operating system provides to users,
how they are provided, and what are the various methodologies
are for designing such systems.
To discuss the various ways of structuring an operating system.
To explain how operating systems are installed and customized and
how they boot.
Operating System Services
OS provides an environment for the execution of programs. It provides
certain services to programs and to the users of those programs.
One set of operating-system services provides functions that are
helpful to the user:
i. User interface - Almost all operating systems have a user interface (UI).
This can take several forms. Varies between Command-Line (CLI),
Batch interface, Graphics User Interface (GUI),
ii. Program execution - The system must be able to load a program into
memory and to run that program, end execution, either normally or
abnormally (indicating error)
iii. I/O operations - A running program may require I/O, which may involve
a file or an I/O device.
iv. File-system manipulation - The file system is of particular interest.
Obviously, programs need to read and write files and directories, create
and delete them, search them, list file Information, permission
management.
Operating System Services (Cont.)
One set of operating-system services provides functions that are
helpful to the user (Cont):
v. Communications – Processes may exchange information, on the same
computer or between computers over a network. Communications
may be via shared memory or through message passing (packets
moved by the OS)
vi. Error detection – OS needs to be constantly aware of possible errors.
May occur in the CPU and memory hardware, in I/O devices, in
user program For each type of error, OS should take the appropriate
action to ensure correct and consistent computing.
Debugging facilities can greatly enhance the user’s and programmer’s
abilities to efficiently use the system.
Operating System Services (Cont.)
Another set of OS functions exists not for helping the user but rather for
ensuring the efficient operation of the system itself via resource sharing.
Resource allocation - When multiple users or multiple jobs running
concurrently, resources must be allocated to each of them.
Accounting - To keep track of which users use how much and what
kinds of computer resources.
Protection and security - The owners of information stored in a
multiuser or networked computer system may want to control use of
that information, concurrent processes should not interfere with each
other
Protection involves ensuring that all access to system resources is
controlled
Security of the system from outsiders requires user authentication,
extends to defending external I/O devices from invalid access
attempts
User Operating System Interface
There are two fundamental approaches for users to
interface with the operating system. They are CLI and GUI
Command Line Interface(CLI) allows direct command entry.
Some operating system include command interpreter in the
kernel, sometimes by systems program
Sometimes multiple flavors implemented – shells
For example on UNIX and LINUX systems, there are
several different shells a user may choose from including
the Bourne Shell, C Shell Korn Shell.
Primarily fetches a command from user and executes it
– Sometimes commands built-in, sometimes just names of
programs
User Operating System Interface
A second strategy for interfacing with the OS is through Graphical User
Interface.
It provides User-friendly desktop metaphor interface
Usually mouse is moved to position its pointer on images, or icons, on the
screen that represent files, programs, actions, etc
Various mouse buttons over objects in the interface cause various actions
(provide information, options, execute function, open directory (known as a
folder)
Many systems now include both CLI and GUI interfaces
Microsoft Windows is GUI with CLI “command” shell
Apple Mac OS X as “Aqua” GUI interface with UNIX kernel underneath
and shells available
Solaris is CLI with optional GUI interfaces (Java Desktop, KDE)
System Calls
Programming interface to the services is provided by the OS
Typically written in a high-level language (C or C++)
Mostly accessed by programs via a high-level Application
Program 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)
Why use APIs rather than system calls?
Reason is : *) Portability *) System calls are more detailed and
difficult to work with
(Note that the system-call names used throughout this text are
generic)
Example of System Calls
System call sequence to copy the contents of one file to another file
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 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 (set of functions built
into libraries included with compiler)
API – System Call – OS Relationship
Standard C Library Example
C program invoking printf() library call, which calls write() system call
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
Parameter Passing via Table
Types of System Calls
System calls are roughly grouped into 5 major categories. They are:
Process control
File management (manipulation)
Device management (manipulation)
Information maintenance
Communications
Summary of Types of system calls by OS
Process control
end, abort
load, execute
create 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
get and set file attributes
Contd..
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 regions
transfer status information
attach and detach remote devices
Examples of Windows and UNIX System Calls
Process Control
A running program needs to be able to halt its execution
normally(end) or abnormally(abort).
When execution is stopped abnormally, often a dump of
memory is taken and can be examined with a debugger.
Following are functions of process control:
i. end, abort
ii. load, execute
iii. create process, terminate process
iv. get process attributes, set process attributes
v. wait for time
vi. wait event, signal event
vii. allocate and free memory
MS-DOS execution
(a) At system startup (b) running a program
FreeBSD Running Multiple Programs
File management
We first need to be able to create and delete files. Either system call
requires the name of the file and perhaps some of the file's attributes.
Once the file is created, we need to open it and to use it. We may
also read, write, or reposition. Finally, we need to close the file,
indicating that we are no longer using it.
We may need these same sets of operations for directories if we have
a directory structure for organizing files in the file system.
In addition, for either files or directories, we need to be able to
determine the values of various attributes and perhaps to reset them
if necessary. File attributes include the file name, a file type,
protection codes, accounting information, and so on
Functions:
create file, delete file
open, close file
read, write, reposition
get and set file attributes
Device Management
A process may need several resources to execute - main memory, disk
drives, access to files, and so on. If the resources are available, they can
be granted, and control can be returned to the user process. Otherwise,
the process will have to wait until sufficient resources are available.
The various resources controlled by the OS can be thought of as
devices. Some of these devices are physical devices (for example,
tapes), while others can be thought of as abstract or virtual devices (for
example, files).
Once the device has been requested (and allocated to us), we can read,
write, and (possibly) reposition the device, just as we can with files.
Functions:
i. request device, release device
ii. read, write, reposition
iii. get device attributes, set device attributes
iv. logically attach or detach devices
Information Maintenance
Many system calls exist simply for the purpose of transferring
information between the user program and the OS. For example,
most systems have a system call to return the current time and date.
Other system calls may return information about the system, such as
the number of current users, the version number of the OS, the
amount of free memory or disk space, and so on.
In addition, the OS keeps information about all its processes, and
system calls are used to access this information. Generally, calls are
also used to reset the process information.
Functions:
i. get time or date, set time or date
ii. get system data, set system data
iii. get and set process, file, or device attributes
Communication
There are two common models of inter-process communication: the
message-passing model and the shared-memory model. In the
message-passing model, the communicating processes exchange
messages with one another to transfer information.
In the shared-memory model, processes use shared memory create
and shared memory attach system calls to create and gain access to
regions of memory owned by other processes.
Recall that, normally, the OS tries to prevent one process from
accessing another process's memory. Shared memory requires that
two or more processes agree to remove this restriction. They can then
exchange information by reading and writing data in the shared areas.
Message passing is useful for exchanging smaller amounts of data,
because no conflicts need be avoided. It is also easier to implement
than is shared memory for inter-computer communication.
Contd..
Shared memory allows maximum speed and convenience of
communication, since it can be done at memory speeds when it
takes place within a computer. Problems exist, however, in the
areas of protection and synchronization between the processes
sharing memory.
Functions:
i. create, delete communication connection
ii. send, receive messages
iii. transfer status information
iv. Attach and Detach remote devices
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
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 – These programs 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.
System Programs (cont’d)
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 for common programming languages
are often 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.
Operating System Design and Implementation
Focus : Discussion on problems we face in designing and implementing an
OS : Design goals, Mechanisms & Policies, Implementation.
No complete solutions to such problems, but some approaches have proved
successful.
Design Goals : Internal structure of different Operating Systems can vary
widely.
Start by defining goals and specifications.
Affected by choice of hardware, type of system
The requirements may be divided into : 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 (Cont.)
Mechanisms & Policy
Important principle to separate
Policy: It determines what will be done.
Mechanism: It determines how to do something.
For example, timer construct is a mechanism for ensuring CPU protection,
but deciding how long the timer is to be set for a particular user is a policy
decision.
The separation of policy from mechanism is a very important principle, it
allows maximum flexibility if policy decisions are to be changed later
Operating System Design and Implementation (Cont.)
Implementation: Once an OS is designed, it must be implemented.
Much variation
Early Oses have been written in assembly language
Then system programming languages like Algol, PL/1
Now , however they are most commonly written in higher-level
languages such as C or C++.
The advantage of using a higher-level language is easier to port to
other hardware.
For example MS-DOS was written in assembly language.
Consequently it is available on only the Intel family of CPUs. The
LINUX OS is written in C and is available on a number of different
CPUs, including Intel 80X86, Motorola, SPARC, MIPS RX000.
Disadvantage of implementing an OS in a higher-level language are
reduced speed and increased storage requirements.
Operating System Structure
General-purpose OS is very large program.
Various ways to structure : Simple Structure, Layered approach,
Micro kernels, Modules.
Simple Structure : Monolithic, No well defined structure, Start
as small, simple, limited systems and then grow, No layers not
divided into modules.
For example MS-DOS – written to provide the most functionality in
the least space, so it was not divided into modules carefully.
Although MS-DOS has some structure, its interfaces and levels of
functionality are not well separated.
Another example of limited structuring is the original UNIX OS.
MS-DOS Layer 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
Enormous amount of functionality crammed into the kernel.
Very minimal layering made of thick, monolithic layers.
This monolithic structure was difficult to implement and
maintain.
UNIX System Structure
Layered Approach
The operating system is divided into a number of layers (levels), each built on
top of lower layers. The bottom layer (layer 0), is the hardware; the highest
(layer N) is the user interface.
Each built on top of the lower layers.
With modularity, layers are selected such that each uses functions (operations)
and services of only lower-level layers.
Main advantage of layered approach is simplifies debugging and system
verification. Each layer is implemented with only those operations provided by
lower-level layers.
Major difficulties with layered approach:
i) Appropriately defining the various layers
ii) Layering is only possible if all function dependencies can be sorted
out into a Directed Acyclic Graph (DAG)
iii) Less efficient than other types. The more layers, the more indirections
from function to function and the bigger the overhead in function calls
Solution ? Return to fewer layers with more functionality are being designed.
Layered Operating System
Microkernel System Structure
A microkernel is a reduced operating system core that contains only
essential O/S functions
The idea is to minimize the kernel by moving up as much functionality as
possible from the kernel into user space.
Communication takes place between user modules using message passing
Benefits of this approach:
Extensibility: Easier to extend a microkernel
Portability : Easier to port the operating system to new architectures
Reliability and security : Less code is running in kernel mode; failures
in user-space services don’t affect kernel space
Detriment :
Performance overhead of user space to kernel space communication.
Not always realistic: some functions (I/O) must remain in kernel space,
forcing a separation between “policy” and “mechanism”
Modular Approach
Modular approach:
Many modern operating systems implement kernel modules
It is similar to the object oriented approach:
Each core component separate
Each talks to the other over known interfaces
Each is loadable as needed within the kernel
Overall modules are similar to layers but with more functionality.
Modules are also similar to the microkernel approach, except
they are inside the kernel and don’t need message passing modern
operating systems implement kernel modules.
Modules used in Solaris, UNIX and
Approach
Mac OS X Structure
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
A virtual machine provides an interface identical to the underlying bare
hardware
The operating system creates the illusion of multiple processes, each
executing on its own processor with its own (virtual) memory
Virtual Machines (Cont.)
The resources of the physical computer are shared to create the
virtual machines
CPU scheduling can create the appearance that users have
their own processor
Spooling and a file system can provide virtual card readers and
virtual line printers
A normal user time-sharing terminal serves as the virtual
machine operator’s console
Virtual Machines (Cont.)
Non-virtual Machine Virtual Machine
(a) Nonvirtual machine (b) virtual machine
Virtual Machines (Cont.)
The virtual-machine concept provides complete protection of system
resources since each virtual machine is isolated from all other virtual
machines. This isolation, however, permits no direct sharing of
resources.
A virtual-machine system is a perfect vehicle for operating-systems
research and development. System development is done on the
virtual machine, instead of on a physical machine and so does not
disrupt normal system operation.
The virtual machine concept is difficult to implement due to the effort
required to provide an exact duplicate to the underlying machine
VMware Architecture
The Java Virtual Machine
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
SYSGEN program obtains information concerning the specific
configuration of the hardware system
The OS is normally distributed on disk or CD-ROM.
The following kinds of information must be determined.
What CPU is to be used? What options are installed ?
How much memory is available?
What Devices are available?
What operating system options are desired , or what parameter
values are to be used?
System Boot
Booting – starting a computer by loading the kernel
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
Sometimes two-step process where boot block at fixed
location loads bootstrap loader
When power initialized on system, execution starts at a fixed
memory location
Firmware used to hold initial boot code
End of Chapter 2