Download Operating-System Structures

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Mobile operating system wikipedia , lookup

Library (computing) wikipedia , lookup

Security-focused operating system wikipedia , lookup

Plan 9 from Bell Labs wikipedia , lookup

OS 2200 wikipedia , lookup

DNIX wikipedia , lookup

Copland (operating system) wikipedia , lookup

RSTS/E wikipedia , lookup

Burroughs MCP wikipedia , lookup

Process management (computing) wikipedia , lookup

Distributed operating system wikipedia , lookup

VS/9 wikipedia , lookup

Spring (operating system) wikipedia , lookup

Paging wikipedia , lookup

Unix security wikipedia , lookup

CP/M wikipedia , lookup

Transcript
Operating-System Structures
Source: Operating System Concepts by Silberschatz, Galvin and Gagne
CSC 4103: Operating Systems
2.1
B. B. Karki, LSU
OS Basics
 Explore
 What components OS has
 What services OS provides
 How they are provided: Structuring OS, Installation, Customization, Boot
 OS Components
 OS Services
 User OS Interface
 System Calls and Their Types
 System Programs
 OS Design and Implementation
 OS Structure: Layered approach, Microkernels, Modules, Virtual machines
 OS Generation
 System Boot
CSC 4103: Operating Systems
2.2
B. B. Karki, LSU
Common Operating System Components
 OS is large and complex system:
 Consists of different components, each with well defined
inputs, outputs and functions
 A modern OS supports the following components:
 Process Management
 Main Memory Management
 File Management
 I/O System Management
 Secondary-Storage Management
 Networking
 Protection System
CSC 4103: Operating Systems
2.3
B. B. Karki, LSU
Process Management
 A process is a program in execution. It is the unit of work in a system.
 It can be running a program or job (e.g., word-processing program, compiler
program, sending output to a printer, simulation program)
 System consists of a collection of processes related to OS and user
 A process needs resources (CPU time, memory space, files, and I/O
devices) to accomplish its task.
 A process may require input (or initialization data).
 The OS is responsible for all process management activities:
 process creation and deletion.
 process suspension and resumption (scheduling).
 mechanisms for:
 process synchronization
 process communication
 deadlock handling.
CSC 4103: Operating Systems
2.4
B. B. Karki, LSU
Main-Memory Management
 Main memory – an array of words or bytes, each with its own
address
 A repository of quickly accessible data shared by the CPU and I/O
devices.
 Programs, with the data they access, must be in main memory for
the CPU to execute them.
 OS is responsible for all memory management activities:
 tracking which parts of memory are currently being used and by
whom.
 deciding which processes to load when memory space becomes
available.
 allocating and de-allocating memory space as needed.
CSC 4103: Operating Systems
2.5
B. B. Karki, LSU
File Management
 Computers can store information in different physical media (e.g.,
disks, tapes).
 OS provides a logical (an abstract) view of information storage, i.e.,
define a logical storage unit called the file.
 OS maps files into physical media, and accesses these files via the
storage devices such as disk drive.
 A file is a collection of related information (program or data) defined
by its creator.
 OS is responsible for all file management activities:
 file creation and deletion.
 directory creation and deletion.
 support of primitives for manipulating files and directories.
 mapping files onto secondary storage.
 file backup on stable (nonvolatile) storage media.
CSC 4103: Operating Systems
2.6
B. B. Karki, LSU
I/O System Management
 OS hides the peculiarities of specific hardware devices from
the user by defining an I/O subsystem.
 The I/O subsystem consists of:
 buffering, caching, and spooling
 a general device-driver interface
 drivers for specific devices
 The I/O subsystem interfaces to other system components,
manages devices, transfers data, and detects I/O completion.
CSC 4103: Operating Systems
2.7
B. B. Karki, LSU
Secondary-Storage Management
 The computer system must provide secondary storage to back
up main memory.
 Disk used as both the source and destination for processing
 OS is responsible for disk management activities:
 free space management
 storage allocation
 disk scheduling.
CSC 4103: Operating Systems
2.8
B. B. Karki, LSU
Networking
 Networking is of primary concern in a distributed system
which is a collection processors that do not share memory or
a clock.
 Different processors are connected through a communication
network.
 Network design should consider
 Message routing
 Connection strategies
 Security
 Communication takes place using a protocol.
 e.g., FTP, NFS, http
CSC 4103: Operating Systems
2.9
B. B. Karki, LSU
Protection System
 Protection refers to a mechanism for controlling access
by programs, processes, or users to both system and
user resources.
 The protection mechanism must:
 distinguish between authorized and unauthorized usage.
 specify the controls to be imposed.
 provide a means of enforcement.
CSC 4103: Operating Systems
2.10
B. B. Karki, LSU
OS Services
Provide certain services to programs and to the users of those programs:
 User interface: command-line, batch interface and GUI
 Program execution: system capability to load a program into memory and
to run it.
 I/O operations: A running program may require I/O, which may involve a
file or an I/O device.
 File-system manipulation: program capability to read, write, create, and
delete files.
 Communications: exchange of information between processes executing
either on the same computer or on different systems tied together by a
network. Implemented via shared memory or message passing.
 Error detection: ensure correct computing by detecting errors in the CPU
and memory hardware, in I/O devices, or in user programs.
CSC 4103: Operating Systems
2.11
B. B. Karki, LSU
Additional OS Functions
Additional functions exist not for helping the user, but rather for
ensuring efficient system operations:
•
Resource allocation – allocating resources to multiple users or
multiple jobs running at the same time.
•
Accounting – keep track of and record which users use how
much and what kinds of computer resources for account billing
or for accumulating usage statistics.
•
Protection – ensuring that all access to system resources is
controlled.
CSC 4103: Operating Systems
2.12
B. B. Karki, LSU
User OS Interface
 Two common approaches for users to interface with OS.
 Command line interface (CLI) or command interpreter
 Shell: program that is executed automatically when a job is initiated
or a user logs on.
 Get and execute the next user-specified command
 UNIX
 Graphical user interface (GUI)
 Mouse-based window-and-menu system
 Icons representing files, programs, actions, etc.
 Windows
 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)
CSC 4103: Operating Systems
2.13
B. B. Karki, LSU
System Calls
 System calls provide an interface between a process and the OS.
 Typically written in a high-level language (C or C++)
 Even simple programs make heavy use of OS
 But users never see this level of detail.
 Mostly accessed by programs via a high-level application program
interface (API) rather than direct system call use
 Win32, POSIX and Java APIs.
CSC 4103: Operating Systems
2.14
B. B. Karki, LSU
Example of System Calls
 System call sequence to copy the contents of one file to another file
CSC 4103: Operating Systems
2.15
B. B. Karki, LSU
Example of Standard API
 Consider the ReadFile() function in the
 Win32 API—a function for reading from a file
 A description of the parameters passed to ReadFile()
 HANDLE file—the file to be read
 LPVOID buffer—a buffer where the data will be read into and written from
 DWORD bytesToRead—the number of bytes to be read into the buffer
 LPDWORD bytesRead—the number of bytes read during the last read
 LPOVERLAPPED ovl—indicates if overlapped I/O is being used
CSC 4103: Operating Systems
2.16
B. B. Karki, LSU
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)
CSC 4103: Operating Systems
2.17
B. B. Karki, LSU
API - System Call - OS Relationship
CSC 4103: Operating Systems
2.18
B. B. Karki, LSU
System Call Parameter Passing
 Methods to pass parameters between running program and OS.
 Pass parameters in registers.
 Store parameters in a table or a block in memory, and the table
address is passed as a parameter in a register.
 Push (store) parameters onto the stack by the program, and pop off the
stack by OS.
CSC 4103: Operating Systems
2.19
B. B. Karki, LSU
Five Categories of System Calls
 Process control
 File management
 Device management
 Information maintenance
 Communications
CSC 4103: Operating Systems
2.20
B. B. Karki, LSU
Process Control
 end, abort
 load, execute
 create process, terminate process
 get process attributes, set process attributes
 wait time
 wait event, signal event
 allocate and free memory
CSC 4103: Operating Systems
2.21
B. B. Karki, LSU
MS-DOS Execution
 The MS-DOS operating
system is a singletasking system:
 The command
interpreter is invoked
when the computer
is started.
 It loads the program
into memory and
runs it.
 It does not create a
new process.
At System Start-up
CSC 4103: Operating Systems
2.22
Running a Program
B. B. Karki, LSU
UNIX Running Multiple Programs
 FreeBSD is a multitasking system:
 Shell of the user’s choice is run on
user’s logging on.
 Shell may continue running while
another program is executed.
 Shell executes a fork system call to
create a new process; and the
selected program is loaded into
memory via an exec system call and
then executed.
 Process may run interactively or in the
background.
 Exit call once the process is done.
CSC 4103: Operating Systems
2.23
B. B. Karki, LSU
File Management
Common systems calls dealing with files and directories:
 create file, delete file
 open, close
 read, write, reposition
 get file attributes, set file attributes
CSC 4103: Operating Systems
2.24
B. B. Karki, LSU
Device Management
Similarity between files and I/O devices results in similar device
system calls (some OS even merges two into a combined filedevice structure):
 request device, release device
 read, write, reposition
 get device attributes, set device attributes
 logically attach or detach devices
CSC 4103: Operating Systems
2.25
B. B. Karki, LSU
Information Maintenance
System calls for transferring information between the user program
and OS:
 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
CSC 4103: Operating Systems
2.26
B. B. Karki, LSU
Communication
System calls for transferring information between the user program
and OS:
 create, delete communication connection
 send, receive message
 transfer status information
 attach or detach remote devices
CSC 4103: Operating Systems
2.27
B. B. Karki, LSU
Communication Models
 Message passing model: Information is exchanged through inter-
process communication facility provided by OS.
 Shared memory model: Processes use map memory system calls to
gain access to regions of memory owned by other processes.
Message Passing
CSC 4103: Operating Systems
Shared Memory
2.28
B. B. Karki, LSU
System Programs
 System programs provide a convenient environment for program
development and execution. They can be divided into:
 File management: Manipulate files and directories
 Status information: Date, disk space, number of users
 File modification: Text editors
 Programming language support: Compilers, assemblers, debuggers, etc.
 Program loading and execution: Loaders, linkage editors
 Communications: Connection, messages, remote login, data transfer
 Most users’ view of the operation system is defined by system
programs, not the actual system calls. The system programs are
actually user interfaces to system calls.
 Application programs or system utilities
 Web browsers, word processors, text formatters, spreadsheets,
compilers, plotting, games.
CSC 4103: Operating Systems
2.29
B. B. Karki, LSU
System Design Goals
 Designing a system requires defining specifications and
goals of the system.
 Specifications – choice of hardware and type of system:
 Goals - user and system level
 No unique solution to the problem of defining the
requirements for an OS.
 Different requirements can result in a large variety of
solutions for different systems
CSC 4103: Operating Systems
2.30
B. B. Karki, LSU
Mechanisms and Policies
 Mechanisms determine how to do something.
 Policies decide what will be done.
 The separation of policy from mechanism allows maximum
flexibility:
 Policy decisions can be changed later
 Microkernel-based OS implements a basic set of primitive
building blocks which are almost policy free.
 Policy decisions must be made for all resource-allocation and
scheduling problems.
CSC 4103: Operating Systems
2.31
B. B. Karki, LSU
System Implementation
 Once an OS is designed, it must be implemented.
 Traditionally written in assembly language, OS can now be
written in higher-level languages such as C or C++.
 MS-DOS in Intel 8088 assembly language
 Linux in C
 An OS is easier to port (move to some other hardware) if it is
written in a high-level language.
CSC 4103: Operating Systems
2.32
B. B. Karki, LSU
OS Structures
 Organization of OS components to specify the privilege with which each
component executes.
 Four structures
 Monolithic: All components contained in the kernel
 Layered: Top-down approach to separate the functionality and features
into components.
 Microkernel: Only essential components included in the kernel
 Modules: Object-oriented structure
 Virtual Machines: Run on the top of any OS
 VMware and the Java Virtual machine
CSC 4103: Operating Systems
2.33
B. B. Karki, LSU
MS-DOS System Structure
 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
CSC 4103: Operating Systems
2.34
B. B. Karki, LSU
UNIX System Structure
 UNIX OS consists of two separable parts.
 Systems programs
 Kernel is everything between the system-call interface and physical hardware
and has a large amount of functionality.
CSC 4103: Operating Systems
2.35
B. B. Karki, LSU
Layered Approach
 OS 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.
 Design and implementation of OS get simplified in the layered approach.
CSC 4103: Operating Systems
2.36
B. B. Karki, LSU
OS/2 Layer Structure
 A descendant of MS DOS with multitasking and dual-mode operation.
CSC 4103: Operating Systems
2.37
B. B. Karki, LSU
Microkernel Structure
 Moves as much from the kernel into “user” space.
 Result is a smaller kernel.
 Microkernel provides communication facility, and minimal
process and memory management.
 Communication between user modules or services using
message passing.
 Benefits:
 Easier to extend OS as new services are added to user space
 Easier to port OS to new architectures due to smaller kernel
 More reliable and secure (less code is running in kernel mode)
CSC 4103: Operating Systems
2.38
B. B. Karki, LSU
Windows NT Client-Server Structure
 Various applications (Win32, OS/2, and POSIX) run in user space.
 Server for each application runs in user space.
 Message passing between client application programs and
application servers runs in kernel space.
CSC 4103: Operating Systems
2.39
B. B. Karki, LSU
Modules
 Most modern operating systems implement 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
Solaris
Modular
Approach
CSC 4103: Operating Systems
2.40
B. B. Karki, LSU
Mac OS X Structure
 Uses a hybrid structure
 Below top layers is the kernel environment: Mach microkernel and
BSD kernel.
CSC 4103: Operating Systems
2.41
B. B. Karki, LSU
Virtual Machines
 A virtual machine:
 Treats hardware and
OS kernel as though
they were all hardware.
 Application programs
view everything under
them as though the
latter were a part of the
machine itself
 A virtual machine
provides an interface
identical to the
underlying bare
hardware.
 OS creates the illusion
of multiple processes,
each executing on its
own processor with its
own (virtual) memory.
CSC 4103: Operating Systems
Non-virtual Machine
2.42
Virtual Machine
B. B. Karki, LSU
Advantages/Disadvantages of VMs
 Provides complete protection of system resources since each virtual
machine is isolated from all others.
 Allows system development without disrupting normal system
operation.
 Is becoming popular as a means of solving system compatibility
problems.
 Sun Microsystems includes a virtual Intel machine (built on the top of its
native processor) to run Windows OS and applications.
 Intel instructions need to be translated into native instruction.
 Difficult to implement due to the effort required to provide an exact
duplicate to the underlying machine.
 Virtual user and virtual monitor modes.
CSC 4103: Operating Systems
2.43
B. B. Karki, LSU
VMware
 VM Architecture: Abstracts Intel 80X86 hardware into isolated virtual
machines to run several guest operating systems as independently.
CSC 4103: Operating Systems
2.44
B. B. Karki, LSU
Java Virtual Machine
 Compiled Java programs are platform-neutral bytecodes executed
by a Java Virtual Machine (JVM).
 JAVA runs on a virtual machine.
 JVM consists of
 class loader
 class verifier
 runtime
interpreter
 Just-In-Time (JIT) compilers increase performance:
 Transforms the architecture-neutral bytecodes into the host machine
language.
CSC 4103: Operating Systems
2.45
B. B. Karki, LSU
System Generation (SYSGEN)
 Operating systems are designed to run on any class of
machines:
 The system must be configured for each specific computer type –
a process called SYSGEN (system generation).
 SYSGEN program obtains information on specific configuration
of the hardware system and specific OS options.
 CPU, memory, devices.
 The OS is adopted with recompilation, linking-libraries or
executables.
 Booting – starting a computer by loading the kernel.
 Bootstrap program – code stored in ROM that is able to locate the
kernel, load it into memory, and start its execution.
CSC 4103: Operating Systems
2.46
B. B. Karki, LSU
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
 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
CSC 4103: Operating Systems
2.47
B. B. Karki, LSU
Summary
 OS provides a number of services.
 Lowest level: system calls allow a running program to make direct requests from OS.
 Higher level: command interpreter or shell provides a mechanism to issue a request
without writing a program.
 System calls provide basic functions, such as process control, I/O requests,
status control, communication.
 Design becomes flexible with separation of policy and mechanism.
 OS is now written in a higher-level language.
 A layered approach or microkernel results in modularity.
 Virtual-machine concept treats both the OS kernel and hardware as though
they were all hardware
 JVM provides an architectural-neutral interface.
 SYMGEN creates an OS for a particular machine configuration.
CSC 4103: Operating Systems
2.48
B. B. Karki, LSU