Sie sind auf Seite 1von 59

Operating-System Structures

 System Components
 Operating System Services
 System Calls
 System Programs
 System Structure
 Virtual Machines
 System Design and Implementation
 System Generation
Operating system components
Common System Components

 Process Management
 Main Memory Management
 File Management
 I/O System Management
 Secondary Management
 Networking
 Protection System
 Command-Interpreter System
Process Management

 A program does nothing unless its instructions are


executed by a CPU.
 A process can be thought of as a program in execution,
◦ A time-shared user program such as a compiler is a
process.
◦ A word-processing program being run by an individual
user on a PC is a process.
◦ A system task, such as sending output to a printer, is
also a process.
 Every program running on a computer
whether it is a background service or an
application is called a process
 Process management is an operating
system’s way of dealing with running
multiple processes at once
◦ most computers contain one processor with
one core, multi-tasking is done by simply
switching processes quickly
 Process management involves computing
and distributing CPU time as well as
other resources
 operating systems allow a process to be
assigned a priority which affects its
allocation of CPU time.
 In many systems, there is a background process
such as the System Idle Process in Windows which
will run when no other process is waiting for the
CPU.
 A process needs certain resources, including CPU
time, memory, files, and I/O devices, to accomplish
its task.
 These resources are either given to the process
when it is created, or allocated to it while it is
running.

 When the process terminates, the operating system


will reclaim any reusable resources.

 program by itself is not a process; a program is a


passive entity, such as the contents of a file stored
on disk, whereas a process is an active entity
 A process is the unit of work in a system
 The application you see (word processor, spreadsheet or
game) is, indeed, a process, but that application may
cause several other processes to begin, for tasks like
communications with other devices or other computers.
 Numerous processes that run without
giving you direct evidence that they ever
exist
 Windows XP and UNIX can have dozens of
background processes running to handle the
network, memory management, disk management,
virus checking and so on.
◦ CPU can only do one thing at a time. In order
to give the appearance of lots of things
happening at the same time, the operating
system has to switch between different
processes thousands of times a second.
How it happens..
 A process occupies a certain amount of RAM. It also makes use of
registers, stacks and queues within the CPU and operating-system
memory space.
 When two processes are multi-tasking, the operating system
allots a certain number of CPU execution cycles to one program.
 After that number of cycles, the operating system makes copies of
all the registers, stacks and queues used by the processes and note
the point at which the process paused in its execution.
 It then loads all the registers, stacks and queues used by the
second process and allow it a certain number of CPU cycles.
 When those are complete, it makes copies of all the registers,
stacks and queues used by the second program, and load the first
program.
 All of the information needed to keep track of a
process when switching is kept in a data package
called a
process control block.
 The process control block typically contains
 An ID number that identifies the process
 Pointers to the locations in the program and its data
where processing last occurred
 Register contents
 States of various flags and switches
 Pointers to the upper and lower bounds of the
memory required for the process
 A list of files opened by the process
 The priority of the process
 The status of all I/O devices needed by the process
 Each process has a status associated with
it. Many processes consume no CPU time
until they get some sort of input.

 For example, a process might be waiting


on a keystroke from the user. While it is
waiting for the keystroke, it uses no CPU
time. While it is waiting, it is “suspended”.
 When the keystroke arrives, the OS
changes its status.
 When the status of the process changes,
from pending to active, or from
suspended to running, the information in
the process control block must be used.
 if the operating system hasn't been carefully
designed, the system can begin to use the vast
majority of its available CPU cycles to swap
between processes rather than run processes.
 it's called Thrashing
 It usually requires some sort of direct user
intervention to stop processes and bring
order back to the system
 In a system with two or more CPUs, the
operating system must divide the
workload among the CPUs
 balance the demands of the required
processes with the available cycles
◦ Asymmetric operating systems use one CPU
for their own needs and divide application
processes among the remaining CPUs.
Symmetric operating systems divide
themselves among the various CPUs,
balancing demand versus CPU availability even
when the operating system itself is all that's
running.
 The operating system is responsible for
the following activities in connection with
process management.
◦ Process creation and deletion.
◦ process suspension and resumption.
◦ Provision of mechanisms for:
◦ process synchronization
◦ process communication
Memory Management
 An operating system’s memory manager
coordinates the use of these various
memory types by tracking which one is
available, which one should be allocated
or de-allocated and how to move data
between them
 This can happen either because one
process requires a large amount of RAM
or because two or more processes
compete for a larger amount of memory
than is available.
 This then leads to constant transfer of
each process’s data to slower storage.
Managing virtual addresses
 If multiple processes are in the memory
at the same time, they must be stopped
from interfering with each other’s
memory
 Each process sees the whole virtual
address space, typically from address 0 up
to the maximum size of virtual memory
as uniquely assigned to it. The operating
system maintains a page tables that
matches virtual addresses to physical
addresses.
 The operating system can also write
inactive memory pages to secondary
storage. This process is called “paging” or
“swapping”. The terminology varies
between operating system
 set up memory boundaries for types of
software and for individual applications
 The I/O operations implemented via
DMA also read and write data in main
memory.

 To improve both the utilization of the


CPU and the speed of the computer's
response to its users, we must keep
several programs in memory.
Main-Memory Management
 Memory is a large array of words or bytes, each with its own
address. It is a repository of quickly accessible data shared by
the CPU and I/O devices.
 Main memory is a volatile storage device. It loses its contents
in the case of system failure.
 The operating system is responsible for the following activities
in connections with memory management:
◦ Keep track of which parts of memory are currently being used and by
whom.
◦ Decide which processes to load when memory space becomes available.
◦ Allocate and deallocate memory space as needed.
File Management
 A file is a collection of related information defined by
its creator. Commonly, files represent programs
(both source and object forms) and data.
 Computers can store information on several different
types of physical media.
◦ Magnetic tape, magnetic disk, and optical disk are the most
common media. Each of these media has its own
characteristics and physical organization
 For convenient use of the computer system, the
operating system provides a uniform logical
view of information storage
 files represent programs (both source and
object forms) and data.
 Data files may be numeric, alphabetic, or
alphanumeric. Files may be free-form (for
example, text files), or may be formatted rigidly
(for example, fixed fields).
 A file consists of a sequence of bits, bytes, lines,
or records whose meanings are defined by their
creators
 File systems are either journaled or non-
journaled.
 A journaled file system is a safer
alternative in the event of a system crash.
If a system comes to an abrupt stop in a
crash scenario, the non-journaled system
will need to be examined by the system
check utilities. On the other hand, a
journaled file systems recovery is
automatic.
 The operating system is responsible for the
following activities in connections with file
management:
◦ 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.
I/O System Management
 The I/O system consists of:
◦ A buffer-caching system
◦ A general device-driver interface
◦ Drivers for specific hardware devices
Secondary-Storage Management
 Since main memory (primary storage) is volatile and too
small to accommodate all data and programs
permanently, the computer system must provide
secondary storage to back up main memory.
 Most modern computer systems use disks as the
principle on-line storage medium, for both programs and
data.
 The operating system is responsible for the following
activities in connection with disk management:
◦ Free space management
◦ Storage allocation
◦ Disk scheduling
Networking (Distributed Systems)
 A distributed system is a collection processors that do
not share memory or a clock. Each processor has its
own local memory.
 The processors in the system are connected through a
communication network.
 Communication takes place using a protocol.
 A distributed system provides user access to various
system resources.
 Access to a shared resource allows:
◦ Computation speed-up
◦ Increased data availability
◦ Enhanced reliability
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.
Command-Interpreter System
 Many commands are given to the operating
system by control statements which deal with:
◦ process creation and management
◦ I/O handling
◦ secondary-storage management
◦ main-memory management
◦ file-system access
◦ protection
◦ networking
Command-Interpreter System
(Cont.)
 The program that reads and interprets
control statements is called variously:

◦ command-line interpreter
◦ shell (in UNIX)

Its function is to get and execute the next


command statement.
Graphical User Interfaces
 A GUI is basically the pictures you see on
the screen that help you navigate your
computer. They include the icons and the
menus.
 Many operating systems allow the user to
install or create any user interface they
desire.
Operating System Services
 One set of operating-system services provides functions that are helpful to the user:
◦ User interface - Almost all operating systems have a user
interface (UI)
 Varies between Command-Line (CLI), Graphics User Interface (GUI),
Batch
◦ 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)
◦ 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. 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)
◦ Communications – Processes may exchange
information, on the same computer or between
computers over a network

◦ 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
Operating System Services (Cont)
◦ 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
 If a system is to be protected and secure, precautions must be
instituted throughout it.
A View of Operating System Services
System Calls
 Is a programming interface to the services
provided by the OS
 Typically written in a high-level language (C or
C++)
 Mostly accessed by programs via a high-level
Application 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)
System Calls
 User programs are not allowed to access
system resources directly. They must ask
the OS to do that for them.
 OS provides a set of functions that can
be called by user programs to request for
OS services. These functions are called
“system calls”
System Calls
 System calls run in kernel mode.
 They can be called by executing a special
instruction (trap or software interrupt) which
causes processor to switch to the kernel mode
and jump to a previously defined location in the
kernel.
 When the system call finishes, processor returns
to the user program and runs in user mode.
System call
 In computing, a system call is how a program
requests a service from an operating
system's kernel.
 This may include hardware related services
(e.g. accessing the hard disk), creating and
executing new processes, and
communicating with integral kernel services
 System calls provide the interface between a
process and the operating system.
 System calls are used whenever a program
needs to access a restricted resource,
 Why use APIs rather than system calls?
◦ System calls differ from platform to platform.
By using a stable API, it is easier to migrate
your software to different platforms.
◦ The API can support multiple versions of the
operating system and detect which version it
needs to use at run time.
 Program portability
◦ A program using an API can compile and run
on any system that supports the same API
◦ Actual system calls can often be more
detailed and difficult to work with than the
API available to an application programmer.
API (Application Programming
Interface)
 An API is a set of functions provided by an
operating system or other system software.
 An application program calls the functions to
request the services.
 An API clearly defines how to call functions and
what the results are.
 Examples: APIs for file system, graphics user
interface, networking, etc.
 Whenever a program invokes a system
call, it is interrupted.
 CPU then starts executing in the kernel
mode and a routine corresponding to the
system call is executed.
 After the completion of that routine the
control is transferred to the user mode
and the program is restored.
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 (API) invokes
intended system call in OS kernel
API – System Call – OS Relationship
Standard C Library Example
 C program invoking printf() library call, which calls
write() system call
System Call Parameter Passing
 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
 Exact type and amount of information vary according to
OS and call
Parameter Passing via Table
Types of System Calls
 Process control
 File management
 Device management
 Information maintenance
 Communications
 Protection
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
 get file attributes, set file attributes
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 device attributes
 set device attributes
Communications
 create, delete communication connection
 send, receive messages
 transfer status information
 attach or detach remote devices
Examples of Windows and Unix System Calls

Das könnte Ihnen auch gefallen