Sei sulla pagina 1di 60

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
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
Chapter 2

2.1 OPERATING SYSTEM SERVICES


Operating System Services
• An operating system provides an environment for the
execution of programs.
• It provides certain services to programs and to the
users of those programs.
Operating System Services
• One set of OS services provides functions that are
helpful to the user:
– User Interface
• Almost all operating systems have a user interface (UI)
• Varies between
– Command-Line Interface (CLI) which uses text commands and a
method for entering them,
– Graphical User Interface (GUI) the interface is a window system
with a pointing device to direct choose from menus, and make
selections and a keyboard to enter text,
– Batch Interface in which commands and directives to control those
commands are entered into files, and those files are executed
– 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)
Operating System Services
• One set of OS services provides functions that are
helpful to the user:
– I/O Operations
• A running program may require I/O, which may involve a file or
an I/O device.
– File-system Manipulation
• The file system is of particular interest.
• Process needs to
– read and write files and directories
– create and delete them
– search them
– list file Information
• permission management is also required (to allow or access to
files or directories ).
Operating System Services
• One set of OS services provides functions that are
helpful to the user:
– 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)

– Error Detection
• OS needs to be constantly aware of possible errors
– may occur in the CPU and memory, 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
• 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
– Some (such as CPU cycles, main memory, and file storage) may have
special allocation code.
– Others (such as I/O devices) may have general request and release
code.

– Accounting
• To keep track of which users use how much and what kinds of
computer resources
• Accumulating usage statistics
• Usage statistics may be a valuable tool for researchers who
wish to reconfigure the system to improve computing services.
Operating System Services
• Another set of OS functions exists for ensuring the
efficient operation of the system itself via resource
sharing

– Protection and security in a multi-user computer


system
• The owners of information 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
Chapter 2

2.2 USER OPERATING SYSTEM


INTERFACE
User Operating System Interface - CLI
• Command-line interface or command interpreter that allows
users to directly enter commands that are to be performed by
the operating system Command Line Interface (CLI)
– Sometimes implemented in kernel (e.g. Dos),
– Sometimes by systems program(e.g. in
windows xp)
• On systems with multiple command interpreters to choose
from, the interpreters are known as shells.
• BASH (Bourne-Again SHell ), CSH (C SHell), KSH
(Korn SHell), TCSH on Linux
• CMD on windows XP
User Operating System Interface -
CLI
• There are two general ways in which these
commands can be implemented (Primarily fetches a
command from user and executes it)
– Sometimes commands built-in,
• the number of commands that can be given determines the size of
the command interpreter, since each command requires its own
implementing code.
– Sometimes just names of programs
• adding new features doesn’t require shell modification
(e.g. rm file.txt)
• uses the command to identify a file to be loaded into memory and
executed.
User Operating System Interface - GUI
• User-friendly desktop 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

• Many systems now include both CLI and GUI interfaces


– Microsoft Windows is GUI with CLI “command” or “cmd” shell
– Apple Mac OS X as “Aqua” GUI interface with UNIX kernel
underneath and shells available
– Linux is CLI with optional GUI interfaces (GNOM, KDE)
Touchscreen Interfaces

• Because a mouse is
impractical for most mobile
systems, smartphones and
handheld tablet computers
typically use a touchscreen
interface.
• Touchscreen devices
require new interfaces
Virtual keyboard for text entry
Choice of interface
• The choice of whether to use a command-line or GUI
interface is mostly one of personal preference.
• System administrators who manage computers and
power users who have deep knowledge of a system
frequently use the command-line interface.
– Further, command line interfaces usually make repetitive
tasks easier, in part because they have their own
programmability. For example, if a frequent task requires a
set of command-line steps, those steps can be recorded
into a file, and that file can be run just like a program.
2.3 System Calls
The only way that a process communicate with OS

It provides an interface to the service made available by an OS


System Calls
• Programming interface to the services provided by the OS
• Typically written in a high-level language (C or C++)
– Sometimes written using assembly-language instructions.
• System call Example : System call sequence to copy the contents of one
file to another file
scanf(infile)

scanf(outfile)

fopen(“r”);

fopen(“w”);

fgetc();

fputc();

fclose(infile);

fclose(outfile);

exit();
System Calls
• Mostly accessed by programs via a high-level Application
Program Interface (API) rather than direct system call use
– Each API consists of one or more systems calls.
– APIs are OS specific.

• Three most common APIs are


– Win32 API, Win64 API for Windows,
– POSIX API for POSIX-based systems (including UNIX, Linux, Mac OS X)
– Java API for the Java virtual machine (JVM)

• Why use APIs rather than system calls?


– To provide a simplified method of the use of system calls and hide the
implementation details.
– One benefit of programming according to an API concerns program
portability
• run on any system that supports the same API
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 intercepts function calls in the API and
invokes the necessary system calls within the operating system.
– The system call interface invokes intended system call in OS
kernel and returns status of the system call and any return
values
• The caller needs to know nothing about how the system
call is implemented
– Just needs to obey API and understand what OS will do as a
result of the call
– Most details of OS interface hidden from programmer by API
API – System Call – OS Relationship
System Call Parameter Passing
• Often, more information is required than simple identity of
desired system call
– Exact type and amount of information vary according to OS and
system 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 can be grouped roughly into six
major categories:
– Process control
– File management
– Device management
– Information maintenance
– Communications
– Protection
Types of System Calls
• 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
– read, write, reposition (move, rename, etc.)
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 process, file, or device attributes
– set process, file, or device attributes
Types of System Calls
• Communications
– Create, delete communication connection
– send, receive messages
– transfer status information
– attach or detach remote devices
• Protection provides a mechanism for
controlling access to the resources provided
by a computer system.
Examples of Windows and
Unix System Calls
Chapter 2

2.5 SYSTEM PROGRAMS


Four Components of a Computer System
System Programs
• System programs provide a convenient environment for
program development and execution.(All programs
related to coordinating computer operations)
– Some of them are simply user interfaces to system calls;
others are considerably more complex
• They can be divided into:
• File managemnet
• Status information
• File modification
• Programming language support
• Program loading and execution
• Communications

• The view of OS seen by most users is defined by the


application and system programs, not by the actual
system calls
System Programs
• File management
– create, delete, copy, rename, print, dump, list, and generally
manipulate files and directories

• Status information
– Some programs ask the system for info.
• date, time, amount of available memory, disk space, number of users.
• detailed performance, logging, and debugging information.

– Typically, these programs format and print the output to the


terminal, other output devices, files.
– 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 sometimes provided
System Programs (cont’d)
• Program loading and execution
– Once a program is compiled, it must be loaded into
memory to be executed.
– loaders, debugging systems

• 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
Chapter 2

2.6 OS DESIGN AND IMPLEMENTATION


Operating System Design and Implementation

• Design and Implementation of OS is not “solvable”


– but some approaches have proven successful
• Internal structure of different OS can vary widely
• The first problem in designing a system is define
goals and specifications
• At the highest level, the design of the system will be Affected
by choice of hardware, type of system
• batch, multiprogramming, multitasking
• single user, multi-user
• distributed, real-time, general purpose.
Operating System Design and
Implementation
• Requirements for an OS divided into two basic
groups (User goals and System goals)
– User goals – operating system should be convenient
to use, easy to learn, reliable, safe, and fast
• There is no general agreement on how to achieve them.
– System goals – operating system should be easy to
design, implement, and maintain, as well as flexible,
reliable, error-free, and efficient
• these requirements are not clear and may be interpreted
in various ways.
Operating System Design and
Implementation
• There is, no unique solution to the problem of
defining the requirements for an operating system.
• The wide range of systems in existence shows that
different requirements can result in a large variety of
solutions for different environments.
• For example,
– the requirements for a realtime operating system for
embedded systems, must have been substantially different
from those for a large multiuser, multiaccess operating
system for IBM mainframes.
Operating System Design and Implementation

• Important principle to separate


Policy: What will be done?
Mechanism: How to do it?

• Mechanisms determine how to do something.


• Policies decide 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.
Operating System Design and
Implementation
– The separation of policy from mechanism is a very
important principle,
– it allows maximum flexibility if policy decisions are
to be changed later
• Policies are likely to change across places or
over time.
• For instance, consider a mechanism for giving priority to
certain types of programs over others.
– If the mechanism is properly separated from policy, it can be used
either to support a policy decision that I/O-intensive programs should
have priority over CPU-intensive ones or to support the opposite policy.
Operating System Design and
Implementation
• Once an operating system is designed, it must
be implemented
– Traditionally, written in assembly language.
– Now, written in high-level languages (C: Linux and
Windows)
2.7 OPERATING SYSTEM
STRUCTURE
Operating System Structure
1. Simple Structure
2. Layered Structure
3. Microkernel System Structure
4. Modular Kernel Structure
5. Hybrid Systems
1. Simple/monolithic Structure
• Early operating systems had a monolithic
structure, whereby the OS formed a single
software layer between the user and the bare
machine, i.e., the computer system’s
hardware
1. Simple/monolithic Structure
• By far the most common organization, this
approach might well be subtitled “The Big
Mess.”
• The structure is that there is no structure.
• It runs every basic system service like process
and memory managment, interrupt handling
and I/O communication, file system, etc. in
kernel space
1. Simple/monolithic Structure
• The inclusion of all basic services in kernel
space has three big drawbacks:
– the kernel size, lack of extensibility and the bad
maintainability.
– Bug fixing or the addition of new features means
a recompilation of the whole kernel.
– This is time and resource consuming because the
compilation of a new kernel can take several hours
and alot of memory.
1. Simple/monolithic Structure
• MS-DOS
– Policy - 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
• For instance, application programs are able to access
the basic I/O routines to write directly to the display
and disk drives, causing entire system crashes when
user programs fail.
1. Simple Structure
• MS-DOS was also
limited by the hardware
of its era.
– Because the Intel 8088
for which it was written
provides no dual mode
and no hardware
protection, the designers
of MS-DOS had no
choice but to leave the
base hardware
accessible.
2. 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.

• With modularity, layers are selected such that each


uses functions (operations) and services of only lower-
level layers
– A typical OS layer (layer M) consists of data structure and a
set of routines that can be invoked by higher-level layers.
– Layer M, in turn, can invoke operations on lower-level
layers.
Layered Operating System
Layered Approach
• Advantage
– Simplicity of construction and debugging
– The design and implementation is simplified.
– Each layer is implemented with only those 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.
• Disadvantage
– Each layer adds overhead to the system call; the net result is a system
call that takes longer than does one on a non layered system.
– Appropriately defining the various layers (difficulties in developing a
layered design)
– Because a layer can use only lower-level layers, careful planning is
necessary.
3. Microkernel System Structure
• Make the kernel as light as possible.
– moves as much from the kernel into “user” space
– The main function of the microkernel is to provide
a communication facility between the client
program and the various services that are also
running in user space.
• Communication takes place between user modules
using message passing
– Mach OS from Mellon Univ.
Microkernel
3. Microkernel System Structure
• Advantage
– Easier to extend a microkernel
– Easier to port the operating system to new
architectures
– More reliable (less code is running in kernel mode)
and secure
• Disadvantage
– Performance overhead of user space to kernel
space communication
4. Modular Kernel Structure
• Most modern operating systems implement kernel
modules
– The kernel has a set of core components and dynamically
links to additional services either during boot time or
during run time.

– 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


Modular Kernel Structure

• The Modular kernel approach is similar to the Layered


approach
– The modular kernel approach requires subsystems to interact
with each other through carefully constructed interfaces

• However, the Modular kernel approach differs from the


Layered approach
– The layered kernel imposes a strict ordering of subsystems such
that subsystems at the lower layers are not allowed to invoke
operations corresponding to the upper-layer subsystems.
– There are no such restrictions in the modular-kernel approach,
wherein modules are free to invoke each other without any
constraints.
Hybrid Systems
• Most modern operating systems 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
Summary
• OS provides a number of services
– Functions that are helpful to the user
• user interface, program execution, I/O operation
• file system manipulation, communications, error detection
– Functions that ensure the efficient operation of the system
• resource allocation , accounting, protection and security
• Three types of user interface from OS
– CLI, GUI, Batch Interface
• System calls allow a process to make requests to the OS.
– To send a request, program use system APIs or standard library functions which are
translated into a sequence of system calls.
• Three methods of parameter passing in system call
– Register, Block, Stack
• The separation of policy from mechanism is a very important principle in the
design of OS
• Four types of OS structures
– Simple, Layered, Microkernel, Modular
End of Chapter 2

Potrebbero piacerti anche