View
221
Download
2
Category
Tags:
Preview:
Citation preview
Basic Operating System Functions The main purpose of an operating system is to
make the computer easier to use The operating system manages the resources of
the computer in an attempt to meet overall system goals such as efficiency
The operating system supports a user interface that governs the interactions with programmers, operators, etc
The operating system provides programs with a set of services that can aid in the performance of many common tasks
The operating system provides a run-time environment for the programs being executed
Types of Operating Systems(2/1)
A single-job system is one that runs one user job at a time A multiprogramming system permits several user jobs to
be executed concurrently The operating system takes care of switching the CPU
among the various user job A multiprocessor system is similar to a multiprogramming
system, except that there is more than one CPU available Network operating system: users may login to remote
machines, copy files from one machine to another A distributed operating system manages hardware and
software resources so that a user views the entire network as a single system
Types of Operating Systems(2/2) In a batch processing system, a job is described by a
sequence of control statements stored in a machine-readable form
The operating system can read and execute a series of such job without human intervention
A time-sharing system provides interactive, or conversational access to a number of users
The operating system executes commands as they entered, attempting to provide each user with a reasonably short response time to each command
A real-time system is designed to response quickly to external signals
Real-time systems are used on computers that monitor and control time-critical processes
User Interface
The user interface provided by an operating system is design to serve the needs of the various groups of people who must deal with the computer
The design of user interface is extremely important because it is the part of the system that is experienced by most users
An operating system must also contain service routines to support the user interface
Run-Time Environment(2/1)
An operating system supports a run-time environment for user programs
Nearly all operating systems contain routines that help in performing I/O operations
Service routines can be thought of as defining an extended machine for use by programs during execution
The extended machine is sometimes referred to as a virtual machine
In a multiprogramming operating system, the run-time environment also contains routines that manage the resources of the computer, allocating them to user jobs as needed
Run-Time Environment(2/2) The users generally request operating system functions
by means of some special hardware instruction such as a supervisor call (SVC)
Execution of an SVC instruction generates an interrupt that transfer to an operating service routine
The generation of an interrupt also cause the CPU to switch from user mode to supervisor mode
Restricting the use of privileged instructions forces programs to make use of the services provided by the run-time environment
User programs must deal with the extended machine interface, rather than utilizing the underlying hardware functions directly
Machine-Dependent Operating System Features Interrupt Processing Process Scheduling I/O Supervision Management of Real Memory Management of Virtual Memory
Interrupt Processing An interrupt is a signal that causes a computer to alter its
normal flow of instruction execution Such signals can be generated by many different
conditions, such as the completion of an I/O operation, the expiration of a preset time interval, or an attempt to divide by zero
The interrupt automatically transfers control to an interrupt-processing routine (also called an interrupt handler)
The interrupt-processing routine is designed to take some action in response to the condition that caused the interrupt
After completion of the interrupt processing, control can be returned to the point at which the execution was interrupted
SIC/XE Interrupt Type
When an interrupt occurs, the status of the CPU is saved, and control is transferred to an interrupt-processing routine
There is a fixed interrupt work area corresponding to each class of interrupt
Context Switching
The saving and restoring of the CPU status and register are often called context switching operations
The status word SW contains several pieces of information that are important in the handling of interrupts
Saving SW automatically preserves the condition code value that was being used by the interrupted process
IDLE specifies whether the CPU is executing instructions or is idle
ID contains a 4-bit value that identifies the user program currently being executed
MASK MASK is used to control whether interrupts are allowed It is necessary to prevent certain interrupts from occurring
which the first one is being processed This is accomplished by using the MASK field If a bit in MASK is set to 1 (0), interrupts of the
corresponding class are (not) allowed to occur When interrupts are prohibited, they are said to be masked An interrupt that is being temporarily delayed is said to be
pending Each class of interrupt on a SIC/XE machine is assigned
an interrupt priority The pending interrupt with the highest priority is
recognized first
Process Scheduling(3/1)
A process, sometimes called task, is defined as a program in execution
Process scheduling is the management of the CPU by switching control among the various competing processes according to some scheduling policy
A process is created when a user job begins execution, and this process is destroyed when the job terminates
A process is running when it is actually executing instructions using the CPU
A process is blocked if it must wait for some event to occur before it can continue execution
Processes that are neither blocked nor running are said to be ready
Process Scheduling(3/2) A time-slice is a maximum amount of CPU time the
process is allowed to use before giving up control If this time expires, the process is removed from the
running state and placed in the ready state The operating system then selects some process from
the ready state, according to its scheduling policy The selection of a process, and the transfer of control to
it, is called dispatching The part of the operating system that performs this
function is known as the dispatcher Before it has used all its assigned time-slice, a running
process may find that it must wait for the occurrence of some event
In such a case, the running process enters the blocked state, and a new process is dispatched
Process Scheduling (3/3) Each time a process leaves the running state, its current
status must be saved This status must be restored the next time the process is
dispatched The status information for each process is saved by the
operating system in a process status block (PSB) A PSB is created when a process first begins execution
and is deleted when that process terminates The event to be awaited or signaled is specified by giving
the address of an event status block (ESB) that is associated with the event
One or more of the processes that were made ready has a higher priority than the currently running process, the dispatcher would transfer control to the highest priority process that is currently ready
This scheme is known as preemptive process scheduling
I/O Supervision (2/1) On a typical small computer, input and output are usually
performed 1 byte at a time More advanced computers often have special hardware
to take care of the details of transferring data and controlling I/O devices
This function is performed by simple processors known as I/O channels
The sequence of operations to be performed by a channel is specified by a channel program, which consists of a series of channel command
To perform an I/O operation, the CPU executes a Start I/O (SIO) instruction, specifying a channel number and the beginning address of a channel program
The channel then performs the indicated I/O operation without further assistance from the CPU
I/O Supervision (2/2)
After completing its program, the channel generates an I/O interrupt
Each channel operates independently of the CPU, so the CPU is free to continue computing while the I/O operations are carried out
The system must accept I/O requests from use programs and inform these programs when the requested operations have been completed
It must also control the operation of the I/O channels and handle the I/O interrupts generated by the channels
Processing I/O Request The channel work area contains the starting address of
the channel program currently being executed and the address of the ESB corresponding to the current operation
When an I/O operation is completed, the outcome is indicated by status flags that are stored in the channel work area
If the channel status flags indicate some abnormal condition, the operating system initiates the appropriate error-recovery action
After its processing is complete, the interrupt handler ordinarily returns control by restoring the status of the interrupted process
If the CPU was idle at the time of the interrupt, the dispatcher must be invoked
Management of Real Memory (5/1) Many multiprogramming and multiprocessing system
divide memory into partitions, with each process being assigned to a different partition
These partitions may be predefined in size and position (fixed partitions), or they may be allocated dynamically according to the requirements of the jobs being executed (variable partitions)
A simple allocation scheme using fixed partitions loads each incoming job into the smallest free partition in which it will fit
Once it is loaded into a partition, a job remains until its execution is completed
After the job terminates, its partition becomes available for reuse
The initial selection of the partition sizes is very important in a fixed partition scheme
Management of Real Memory (5/2) The fixed partition technique is most effective when the
sizes of jobs tend to cluster around certain common values, and when the distribution of job sizes does not change frequently
Variable memory partition: a new partition is created for each job to be loaded
This newly created partition is of exactly the size required to contain the job
When a job terminates, the memory assigned to its partition is released, and this memory then become available for use in allocating other partitions
Initially, all memory except that assigned to the operating system is unallocated because there are no predefined partitions
Management of Real Memory (5/3) When variable partitions are used, the operating system
needs to maintain a linked list of free memory areas The partition is placed either in the first free area in which
it will fit (first-fit allocation), or in the smallest free area in which it will fit (best-fit allocation)
When a partition is released, its assigned memory is returned to the free list and combined with any adjacent free areas
When a job is running in one partition, it must be prevented from modifying memory location in any other partition or operating system
Bounds registers contains the beginning and ending addresses of a job’s partition
The operating system sets the bounds registers when a partition is assigned to a user job
Management of Real Memory (5/4)
The values in these registers are automatically saved and restored during context switching operations
For every memory reference, the hardware automatically checks the referenced address against the bounds registers
If the address is outside the current job’s partition, the memory reference is not performed and a program interrupt is generated
When the CPU is in supervisor mode, the operating system is allowed to reference any location in memory
Fragmentation occurs when the available free memory is split into several separate blocks, with each block being too small to be used
Management of Real Memory (5/5) After each job terminates, the remaining partitions are m
oved as far as possible toward one end of memory This movement gathers all the available free memory tog
ether into one contiguous block that is more useful for allocating new partitions
The copying of jobs from one location in memory to another may require a substantial amount of time
The use of relocatable partitions creates problems with program relocation
In practice, the implementation of relocatable partituions requires some hardware support
Use a special relocation register that is set by the operating system to contain the beginning address of the program currently being executed
Management of Virtual Memory (6/1)
The virtual memory may be larger than the total amount of real memory available on the computer
The virtual memory used by a program is stored on some external device (backing store)
Portions of the virtual memory are mapped into memory as they are needed by the program
The backing store and the virtual-to-real mapping are completely invisible to the user program
In a typical demand-paging system, the virtual memory of a process is divided into pages of some fixed length
The real memory of the computer is divided into page frames of the same length as the pages
The mapping of pages onto page frames is described by a page map table (PMT); there is one PMT for each process in the system
Management of Virtual Memory (6/2) The PMT is used by the hardware to convert addresses
in a program’s virtual memory into the corresponding addresses in real memory
This conversion of virtual addresses to real addresses is known as dynamic address translation
If a page has not yet been loaded into real memory, it generates a special type of program interrupt called a page fault
The operating system maintains a table describing the status of all page frames
The first step in processing a page fault interrupt is to search this table for an empty page frame
If an empty page frame is found, the required page can be loaded immediately
Otherwise, a page currently in memory must be removed to make room for the page to be loaded
Management of Virtual Memory (6/3) The interrupt handler selects a page frame to receive the
required page and marks this frame as committed so that it will not be selected again because of a subsequent page fault
If a page is to be removed, the PMT for the process that owns that page is updated to reflect its removal
After completion of the paging operation, the interrupt handler uses the saved status information to return control to the instruction that caused the page fault
Least recently used (LRU) method: keep records of when each page in memory was last referenced and replace the page that has been unused for the longest time
Working set of the process: the set of pages that are frequently used by the process
Management of Virtual Memory (6/4) Each process always has its working set in memory Implementation of the page table as arrays in central
memory can be very inefficient because it requires an extra memory access for each address translation
Use a technique in combination with a high-speed buffer to improve average access time
Implement the page map tables in a special high-speed associative memory
This is very efficient, but may be too expensive for systems with large real memories
Demand-paging systems avoid most of the wasted memory due to fragmentation
They also save memory that parts of a program that are not used during a particular execution need not be loaded
Management of Virtual Memory (6/5) The total collapse of service because of a high paging
rate is known as threshing To avoid thrashing, it is necessary for the page fault rate
to be much lower Memory references tend to be clustered together in the
address space Because of locality of reference, it is possible to achieve
an acceptably low page fault rate without keeping all of a program’s address in real memory
If W pages or more are in memory, performance will be satisfactory, where W is the size of the program’s working set of pages
The association of a virtual-memory address with a real-memory address is not made until the memory reference is performed
Management of Virtual Memory (6/6)
In a segmented virtual-memory system, an address consists of a segment number and an offset within the segment being addressed
Segment may be of any length Segment usually correspond to logical program units
such as procedures and data areas The is makes it possible to associate protection
attributes such as read only or execute only with certain segments
It is possible for segments to be shared between different user jobs
Segmentation is often combined with demand paging This combination requires a two-level mapping and
address-translation procedure
Machine-Independent Operating System Features File Processing Job Scheduling Resource Allocation Protection
File Processing (2/1) The file-management function of an operating system is
an intermediate stage between the user program and the I/O supervisor
To convert the program’s logical requests into physical I/O requests, the file manager must have information about the location and structure of the file
It obtains such information from data structures we call the catalog and the file information tables
The catalog relates logical names to their physical locations and may give some basic information about the files
The file information table for a file gives additional information such as file organization, record length and format, and indexing technique.
File Processing (2/2) To begin the processing of a file, the file manager
searches the catalog and locates the appropriate file information table
The file manager may also create buffer areas to receive the blocks being read or written
The initialization procedure is known as opening the file After the processing of the file is completed, the buffers
and any other work areas and pointers are deleted This procedure is called closing the file The use of two buffer allows overlap of the internal
processing of one block with the reading of the text This technique is called double buffering The use of file manager makes the user program much
simpler easier to write, and therefore less error-prone
Job Scheduling (3/1) In a single-job system, the job scheduler completely
specifies the order of job execution In a multiprogramming system, the job scheduler specifies
the order in which jobs enter the set of tasks that are being executed concurrently
Job submitted to the system become part of an input queue; a job scheduler selects jobs from this workload
The jobs selected become active, which means they begin to participate in the process-scheduling operation
This two-stage procedure is used to limit the multiprogramming level
If the system attempts to run too many jobs concurrently, the overhead of resource management becomes too large, and the amount of resources available to each job becomes too small
Job Scheduling (3/2) The job scheduler is used as a tool to maintain a desirable
level of multiprogramming Thrashing occurs when a job does not have a certain
number of pages in memory, and the performance of the overall system suffers
The number of pages a job requires to prevent thrashing is difficult to predict and the critical number of pages may change considerably during the execution of the program, so the desired level of multiprogramming may change during the operation of the system
Intermediate-level scheduler: monitors system performance and adjusts the multiprogramming level as needed
Job Scheduling (3/3) Turnaround time: the time between the submission of a
job by a user and the completion of that job Response time: the length of time between entering a
command and beginning to receive a response from the system
High throughput and low average turnaround time or response time are commonly accepted as desirable system characteristics
First come-first served (FCFS) tends to treat all jobs equally, so it minimizes the range of turnaround time
Shortest job first (SJF) provides a lower average turnaround time because it runs short jobs much more quickly; however, long jobs may be forced to wait a long time for service
Resource Allocation Deadlock: a set of processes each of which is
permanently blocked because of resources held by the other
Once a deadlock occurs, the only solution is to release some of the resources currently being held; this usually means canceling one or more of the jobs involved
The system could require that a process request all its resources at the same time, or that it request them in a particular order, which can degrade the overall operation of the system
The problem we have discussed are examples of the more general problems of mutual exclusion and process synchronization
Protection (2/1)
Most multi-user operating systems provide some type of access control or authorization mechanism, which is often based on an access matrix
Access rights to newly created object are usually specified by the creator of that object
The information concerning access rights is often stored as an authorization list (i.e., a list of authorized users) for each object, or as a capability list (i.e., a list of objects that can be accessed) or each user
One of the most common methods for user identification is a system of passwords
Protection (2/2)
A system of user identification and authorization does not always solve the overall security problem, because information must sometimes leave the secure environment
Information to be sent over a nonsecure communication link is encrypted (encoded) which still in the secure environment of the sender
The transmitted information is decrypt (decoded) after entering the secure environment of the receiver
The effectiveness of any protection system depends entirely on the correctness and protection of the security system itself
Operating System Design Options
Hierarchical Structure Virtual Machine Multiprocessor Operating Systems Distributed Operating Systems Object-Oriented Operating System
Hierarchical Structure (2/1)
Each layer, or level, of the structure can use the functions provided by lower levels just as if they were part of the real machine
Level 0, often called the kernel of the operating system, deals directly with the underlying hardware
User programs deal with the highest-level interface
Operating system routines at a given level can use the relatively simple functions and interfaces provided by lower levels
Hierarchical Structure (2/2)
The operating system can be implemented and tested one level at a time, this greatly reduces the complexity of each part of the operating system and makes the tasks of implementation and debugging much simpler
In a strict hierarchy, each level may refer only to the level immediately beneath it
This approach has the advantage of simplicity of use, however, such a restriction can lead to inefficiency because it increases the number of calls that must be performed to reach the inner level
In a transparent hierarchy, each level may communicate directly with the interface of any lower level
Virtual Machine (3/1) The virtual-machine approach makes it possible to run
different operating systems concurrently on the same real machine
We can think of virtual machines as an extension of the concept of multiprogramming down to the lowest level of the operating system
Virtual machine monitor (VMM): provides each user with the illusion of running on a separate machine
It is possible to test new operating systems and to allows users with special needs to run in supervisor mode, while at the same time continuing to serve ordinary users in the usual way
The lowest level routines of the operating system deal with the VMM instead of with the real machine
Virtual Machine (3/2) The VMM provides resources, services, and functions
that are the same as those available on the underlying real machine
The VMM simulates the effect of the privileged operation that was being attempted, and then returns control to the user of the virtual machine
The VMM is actually a complete, but simple, operating system for the real machine
The VMM must provide all of the essential machine-dependent functions
The VMM saves status information for each virtual machine and switches the real CPU between the various virtual machine
Virtual Machine (3/3) The most obvious advantages of the virtual-machine
approach are flexibility and convenience Different operating systems can be run concurrently to
serve the needs of different types of users Operating systems and stand-alone programs can be
tested while still making the machine available o ordinary users
The use of separate virtual machines can provide a higher degree of protection since each virtual machine has no access to the resources of any other
The disadvantage is the higher system overhead required to simulate virtual-machine operation
Multiprocessor Operating System (3/1) The process scheduler may have more tan one CPU to
assign to user jobs, so more than one process might be in the running state at the same time
In a loosely coupled system, each processor has its own logical address space and its own memory
In a tightly coupled system, all processors share the same logical address space, and there is a common memory that can be accessed by all processors
These types of multiprocessor organization are sometimes referred to as distributed memory systems and shared memory systems
In a separate supervisor system, each processor has its own operating system
There are some common data structures that are used to synchronize communication between the processors
Multiprocessor Operating System (3/2) Separate supervisor systems are relatively simple, and
the failure of one processor need not affect the others The independence between processors makes it difficult
to perform parallel execution of a single user job In a master-slave system, one “master” processor
performs all the resource management and other operating system functions
The slave processors are treated as resources to be scheduled by the master
It is possible to assign several slave processors to execute a use job in parallel
The most significant problem with master-slave multiprocessing systems is the unbalanced use of resources
Multiprocessor Operating System (3/3) Symmetric processing: all processors have the ability to
perform the same sets of functions, the potential bottlenecks of a master-slave system are avoided
The failure of any one processor will not necessarily cause the entire system to fail
In a symmetric multiprocessing system, different parts of the operating system can be executed simultaneously by different processors
Such a system may be significantly more complicated and more difficult to design than the other types of operating systems
Symmetric multiprocessing systems must provide some mechanism for controlling access to critical operating system tables and data structures
The solution usually requires a special hardware feature that allows one processor to seize control of a critical resource, locking out all other processors in a single step
Distributed Operating Systems (2/1) Network operating system: provide a communication
interface that allows various types of interaction via the network
Distributed operating system: manages hardware and software resources so that a user views the entire network as a single system
The user is not aware of which machine on the network is actually running a program or where the resources being used are actually located
The sharing of resources between computers is made easier
Provide improved performance by distributing the load between computers and executing parts of a task concurrently on several processors
A system can be more reliable , because the failure of one component need not affect the rest of the system
Distributed Operating Systems (2/2) Adding additional processors or other resources can
improve performance without requiring a major change in the system configuration
Communication delays are unpredictable, and there is often no common time reference that can be used as system clock
In order to give the appearance of a unified system, a distributed operating system must provide a consistent interface for users and their programs
The same basic operating system kernel must be used on all machines
These design goals present a substantial challenge to system designers
Object-Oriented Operating Systems (2/1) Objects belong to classes that designate some of the
properties of the object Each object encapsulates a data structure and defines a
set of operations on that data structure The operations defined for objects are called methods When a user program needs to perform some operation
on an object, it does so by invoking one of the methods defined for that object
When a process wants to invoke a method on an object, it sends a message to the server that manages that object
Servers also are responsible for creating new objects and deleting objects that are no longer needed
The kernel of the operating system is relatively small and simple
Object-Oriented Operating Systems (2/2) By invoking methods, processes can request operating
system services, send messages to other processes, and perform remote procedure calls
From the user’s point of view, invoking a method on an object at a remote machine on the network is exactly the same as invoking a method on a local object, thus, distributed applications require no special handling
The details of the implementation are hidden from the invoking process—it sees only the interface by which the invocation is requested
The problem of providing security is simplified Object-oriented operating system will be widely used in
the near future
Recommended