0% found this document useful (0 votes)
4 views

Week 02 Lecture Chapter 2

Chapter 2 discusses the structures and services provided by operating systems, including user interfaces, system calls, and types of system calls. It outlines the design and implementation goals of operating systems, emphasizing the importance of separating mechanisms from policies. Additionally, it covers the organization of operating systems into modules for efficient operation and modification.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Week 02 Lecture Chapter 2

Chapter 2 discusses the structures and services provided by operating systems, including user interfaces, system calls, and types of system calls. It outlines the design and implementation goals of operating systems, emphasizing the importance of separating mechanisms from policies. Additionally, it covers the organization of operating systems into modules for efficient operation and modification.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 69

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.
Operating-System Debugging.
Operating System Generation.
System Boot.
Objectives

To describe the services an operating system provides


to users, processes, and other 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
Operating systems provide an environment for execution of
programs and services to programs and users.
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).
 Varies between Command-Line (CLI), Graphics User
Interface (GUI), Batch Interface.
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.
Operating System Services (Cont.)
IV. File-system manipulation The file system is of particular interest.
Programs need to read and write files and directories, create and
delete them, search them, list file information, permission
management.
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.
 Foreach 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 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
 Many types of resources: CPU cycles, main memory, file
storage, I/O devices.
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 – any mechanism for controlling access of processes or users to resources defined by
the OS. Security – defense of the system against internal and external attacks

Protection involves ensuring th at all access to system

resources is controlled.
Security of th e system from outsiders requires user
authentication, extends to defending external I/O devices from
invalid access attempts.
A View of Operating System Services
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.
User Operating System Interface - CLI

CLI or command interpreter allows direct command entry:


Sometimes implemented in kernel, sometimes by systems
program.
Sometimes multiple flavors implemented – shells.
Primarily fetches a command from user and executes it.
Sometimes commands built-in, sometimes just names of
programs.
If the latter, adding new features doesn’t require shell
modification.
Bourne Shell Command Interpreter
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 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 is “Aqua” GUI interface with UNIX kernel
underneath and shells available
Unix and Linux have CLI with optional GUI interfaces (CDE,
KDE, GNOME)
The Mac OS X GUI
Touchscreen Interfaces

Touchscreen devices require new


interfaces:
Mouse not possible or not
desired.
Actions and selection based on
gestures.
Virtual keyboard for text entry.
Voice commands.
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.
System Calls

It provides an interface to the services made available by an


operating system.
Many system calls exist simply for the purpose of transferring
information between the user program and the operating
system.
Programming interface to the services provided by the OS.
Typically written in a high-level language (C or C++), although
certain low-level tasks may have to be written using assembly-
language instructions. assembly language: human readable
Mostly accessed by programs via a high-level Application
Programming Interface (API) rather than direct system call use.
Example of System Calls
System call sequence to copy the contents of one file to another file.
Example of Standard API

function return type if any


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 then invokes the intended system call in
OS kernel and returns status of the system call and any return
values.
The caller need to know nothing about how the system call is
implemented or what does during execution:
Just needs to obey API and understand what OS will do as a
result of the execution of that system call.
Thus, Most details of OS interface are hidden from the
programmer by API and are managed by run-time support
library (set of functions built into libraries included with
compiler).
API – System Call – OS Relationship

mode bit 1

mode bit 0
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:
1. Simplest: pass the parameters in registers
 In some cases, may be more parameters than registers.
2. 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.
3. 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
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.
Types of System Calls

Process control
File management
Device management
Information maintenance
Communications
Protection
Types of System Calls
Process control:
create process, terminate process.
end, abort.
load, execute.
get process attributes, set process attributes.
wait for time.
wait 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.
Standard C Library Example
C program invoking printf() library call, which calls write() system call.
Types of System Calls

File management:
create, delete file.
open, close file.
read, write, reposition.
get and set file attributes.
Types of System Calls

Device management:
request, release device.
read, write, reposition.
get device attributes, set device attributes.
logically attach or detach devices.
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.
Types of System Calls (Cont.)

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 (Cont.)

Protection
Control access to resources.
Get and set permissions.
Allow and deny user access.
Examples of Windows and Unix System Calls
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.
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.
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 (Cont.)

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.
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.
System Programs (Cont.)

Background Services
Launch at boot time.
 Some for system startup, then terminate.
 Some from system boot to shutdown.
Provide facilities like disk checking, process scheduling, error
logging, printing.
Run in user context not kernel context.
Known as services, subsystems, daemons.
System Programs (Cont.)

Along with the system programs, most operating systems are supplied
with programs that are useful in solving common problems or
performing common operations. Such Application programs, include
Web browsers, word processors and text formatters, spreadsheets,
database systems, compliers, plotting and games.
Don’t pertain to system.
Run by users.
Not typically considered part of OS.
Launched by command line, mouse click, finger poke.
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.
Operating System Design and Implementation
1. Design Goals
Designing and implementing an operating system faced different
problems.
The first problem in designing a system is to define goals and
specifications.
At the highest level, the design of the system will be affected by the
choice of hardware and the type of system: batch, time sharing,
single user, multiuser, distributed, real time, or general purpose.
The requirements can be divided into two basic groups:
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.)
1. Design Goals (Cont.)
Specifying and designing an operating system is a highly creative
task.
Although no textbook can tell you how to do it, general principles
have been developed in the field of software engineering.
Operating System Design and Implementation (Cont.)
2. Mechanisms and Policies
One important principle is the separation of policy from
mechanism.
Mechanism: How to do something.
Policy: What will be done.
For example, the 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
for flexibility. Policies are likely to change across places or
over time.
In the worst case, each change in policy would require a
change in the underlying mechanism. A general mechanism
insensitive to changes in policy would be more desirable.
Operating System Design and Implementation (Cont.)

3. Implementation:
Once an operating system is designed, it must be implemented.
Because operating systems are collections of many programs,
written by many people over a long period of time, it is difficult to
make general statements about how they are implemented.
An operating system can be written in more than one language:
Early OSes in assembly language. 1958- for scientific programming

Then system programming languages like Algol, PL/1.


1964- procedural, imperative computer programming language
Now C, C++. developed and published by IBM.
Operating System Design and Implementation (Cont.)

3. Implementation (Cont.):
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.
The advantages of using a higher-level language, or at least a
systems implementation language, for implementing operating
systems are the same as those gained when the language is used for
application programs: the code can be written faster, is more
compact, and is easier to understand and debug.
Finally, an operating system is far easier to port if it is written in a
higher-level language.
Emulation can allow an OS to run on non-native hardware
effort to match/reproduction of the function or action of a different computer, software system
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.
Operating System Structure
A system as large and complex as a modern operating
system must be engineered carefully if it is to function
properly and be modified easily. A common approach is to
partition the task into small components, or modules, rather
than have one monolithic system. Each of these modules
should be a well-defined portion of the system, with
carefully defined inputs, outputs, and functions.
Various ways to structure ones:
Simple structure – MS-DOS.
More complex – UNIX.
Layered – an abstraction.
Microkernel –Mach.
1. Simple Structure
Many operating systems do not
have well-defined structures.
Frequently, such systems started
as small, simple, and limited
systems and then grew beyond
their original scope.
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.
MS-DOS layer structure
Simple Structure (Cont.)

UNIX – Another example of limited structuring is the original UNIX


operating system. UNIX initially was limited by hardware
functionality.
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.
Traditional UNIX System Structure
Traditional UNIX system structure
2. Layered Approach
 A system can be made modular
in many ways. One method is
the layered approach, in which
the operating system is broken
into a number of layers (levels).
The bottom layer (layer 0) is
the hardware; the highest (layer
N) is the user interface.
 An operating-system layer is an
implementation of an abstract
object made up of data and the
operations that can manipulate
those data.
Layered Approach (Cont.)
 The main advantage of the layered approach is simplicity of construction
and debugging. The layers are selected so that each uses functions
(operations) and services of only lower-level layers. This approach
simplifies debugging and system verification.

 Each layer is implemented only with operations provided by lower-level


layers. A layer does not need to know how these operations are
implemented; it needs to know only what these operations do. Hence,
each layer hides the existence of certain data structures, operations, and
hardware from higher-level layers.

 The major difficulty with the layered approach involves appropriately


defining the various layers. Because a layer can use only lower-level
layers, careful planning is necessary.

 In addition, a layered approach tend to be less efficient than other types.


3. Microkernel System Structure
 Researchers at Carnegie Mellon University developed an operating system
called Mach that modularized the kernel using the microkernel approach.
 This method structures the operating system by removing all nonessential
components from the kernel and implementing them as system and user-
level programs. The result is a smaller kernel.
 Typically, microkernels provide minimal process and memory management,
in addition to a communication facility.
 The main function of the microkernel is to provide communication between
the client program and the various services that are also running in user
space. Communication is provided through message passing.
 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.
3. Microkernel System Structure (Cont.)
Benefits:
 It makes extending the operating system easier.
 All new services are added to user space and consequently do not
require modification of the kernel.
 When the kernel does have to be modified, the changes tend to be
fewer, because the microkernel is a smaller kernel. The resulting
operating system is easier to port from one hardware design to
another.
 The microkernel also provides more security and reliability, since
most services are running as user “rather than kernel” processes. If a
service fails, the rest of the operating system remains untouched.
 Detriments:
The performance of microkernels can suffer due to increased
system-function overhead.
Microkernel System Structure

Application File Device user


Program System Driver mode

messages messages

Interprocess memory CPU kernel


Communication managment scheduling mode

microkernel

hardware
4. Modules
Perhaps the best current methodology for operating-system
design involves using 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.
Solaris Modular Approach
5. Hybrid Systems
Very few operating systems adopt a single, strictly defined
structure. Instead, they combine different structures, resulting in
hybrid systems that address performance, security, and usability
issues.
For Example: both Linux and Solaris are monolithic
The operating system is in a single address space provides very
efficient performance.
they are also modular, so that new functionality can be
dynamically added to the kernel.
Windows is largely monolithic as well (again primarily for
performance reasons), but it retains some behavior typical of
microkernel systems, including providing support for separate
subsystems (known as operating-system personalities) that run as
user-mode processes. Windows systems also provide support for
dynamically loadable kernel modules.
Mac OS X

Apple Mac OS X hybrid, layered, Aqua UI plus Cocoa


programming environment:
Below is kernel consisting of Mach microkernel and BSD Unix
parts, plus I/O kit and dynamically loadable modules (called
kernel extensions).
Mac OS X Structure
graphical user interface
Aqua

application environments and services

Java Cocoa Quicktime BSD

kernel environment
BSD

Mach

I/O kit kernel extensions


iOS
iOS is a mobile operating system designed by
Apple to run its smartphone, the iPhone, as
well as its tablet computer, the iPad. iOS is
structured on the Mac OS X operating system,
with added functionality pertinent to mobile
devices. but does not directly run Mac OS X
applications.
Cocoa Touch is an API for Objective-C
that provides several frameworks for
developing applications that run on iOS
devices.
Media services layer provides services for
graphics, audio, and video
Core services layer provides a variety of
features, including support for cloud
computing and databases.
The bottom layer represents the core
operating system
Android
The Android operating system was designed by the Open Handset
Alliance (led primarily by Google) and was developed for Android
smartphones and tablet computers. Android runs on a variety of mobile
platforms and is open-sourced, partly explaining its rapid rise in
popularity.
Android is similar to iOS in that it is a layered stack of software that
provides a rich set of frameworks for developing mobile applications.
At the bottom of this software stack is the Linux kernel, although it has
been modified by Google.
Linux is used primarily for process, memory, and device-driver support
for hardware and has been expanded to include power management.
Apps developed in Java plus Android API.
Java class files compiled to Java bytecode then translated to executable
than runs in Dalvik VM.
Libraries include frameworks for web browser (webkit), database
(SQLite), multimedia, smaller libc.
Android Architecture

Application Framework

Libraries Android runtime

SQLite openGL Core Libraries

surface media
Dalvik
manager framework
virtual machine
webkit libc
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.
Operating-System Debugging

Debugging is the activity of finding and fixing errors in a system, both


in hardware and in software. Performance problems are considered
bugs, so debugging can also include performance tuning, which seeks
to improve performance by removing processing bottlenecks.
1. Failure Analysis:
If a process fails, most operating systems write the error
information to a log file to alert system operators or users that the
problem occurred.
The operating system can also take a core dump “a capture of the
memory of the process” and store it in a file for later analysis.
A failure in the kernel is called a crash.
When a crash occurs, error information is saved to a log file, and
the memory state is saved to a crash dump.
Operating-System Debugging
2. Performance Tuning:
performance tuning seeks to improve performance by removing
processing bottlenecks. To identify bottlenecks, we must be able to
monitor system performance. Thus, the operating system must have
some means of computing and displaying measures of system
behavior. In a number of systems, the operating system does this by
producing trace listings of system behavior. All interesting events
are logged with their time and important parameters and are written
to a file.
Another approach to performance tuning uses single-purpose,
interactive tools that allow users and administrators to question the
state of various system components to look for bottlenecks. The
Windows Task Manager is a similar tool for Windows systems.
The task manager includes information for current applications as
well as processes, CPU and memory usage, and networking
statistics.
Operating-System Debugging

3. DTrace:
DTrace is a facility that dynamically adds probes to a running system, both
in user processes and in the kernel. These probes can be queried via the D
programming language to determine an astonishing amount about the
kernel, the system state, and process activities.
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.
Operating System Generation
n Operating systems are designed to run on any of a class of
machines; the system must be configured for each specific
computer site.
n SYSGEN program obtains information concerning the
specific configuration of the hardware system.
n The operating system is normally distributed on disk, on CD-
ROM or DVD-ROM, or as an “ISO” image. To generate a
system, we use a special program. This SYSGEN program
reads from a given file, or asks the operator of the system for
information concerning the specific configuration of the
hardware system, or probes the hardware directly to
determine what components are there. The following kinds
of information must be determined. Used to build system-
specific compiled kernel or system-tuned.
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.
System Boot
When power initialized on system, execution starts at a fixed
memory location:
Firmware ROM used to hold initial boot code.
Operating system must be made available to hardware so hardware
can start it:
Small piece of code – bootstrap loader, stored in ROM or
EEPROM locates the kernel, loads it into memory, and starts it.
Sometimes two-step process where boot block at fixed location
loaded by ROM code, which loads bootstrap loader from disk.
Common bootstrap loader, GRUB, allows selection of kernel from
multiple disks, versions, kernel options.
Kernel loads and system is then running.

You might also like