Download Document

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

Plan 9 from Bell Labs wikipedia , lookup

MTS system architecture wikipedia , lookup

Acorn MOS wikipedia , lookup

DNIX wikipedia , lookup

Copland (operating system) wikipedia , lookup

Library (computing) wikipedia , lookup

Distributed operating system wikipedia , lookup

RSTS/E wikipedia , lookup

OS 2200 wikipedia , lookup

Spring (operating system) wikipedia , lookup

Burroughs MCP wikipedia , lookup

Unix security wikipedia , lookup

Paging wikipedia , lookup

Process management (computing) wikipedia , lookup

VS/9 wikipedia , lookup

CP/M wikipedia , lookup

Transcript
Operating System Concepts
Lecture 3 (Chapter 2)
•
•
•
•
•
•
Operating System Services
User Operating-System Interface
System Calls
Types of System Calls
Operating System Design and Implementation
Operating System Structure
Objectives
• To provide an insight about the services provided by OS to
users and designers
• To give a brief knowledge about the factors that are to be
kept in mind for designing the OS
• To give a review on different OS structures which have been
developed so far
Operating System Services
•
OS services for convenience of the users:– User Interface (Command line Interface/ Graphical User Interface): You need an
interface to give instructions, OS provides an environment for execution of
programs
 CLI: Command-line interface (Uses text commands and a method for entering
them, you write commands and press enter, it’s executed)
 Batch Interface: An interface in which your commands are entered into files and
then those files are executed
 GUI: Graphical User Interface (You have a mouse from where you choose your
I/O devices, choose from menus and keyboard to enter text)
– Program execution – system capability to load a program into memory, run, and
end it normally or abnormally.
 Job Scheduling
 CPU scheduling
– I/O operations – since user programs cannot execute I/O operations directly,
the operating system must provide some means to perform I/O.
•
– File-system manipulation – program capability to read, write, create, and
delete files, (permission management)
– 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 approaches.
– Error detection – ensures correct computing by detecting errors in the
CPU and memory hardware, in I/O devices, or in user programs.
OS services for ensuring efficient system utilization:- (Ensuring efficient
operating of OS)
– Resource allocation – allocating resources to multiple users or multiple
jobs running at the same time. (resources like CPU time, main memory, file
storage etc)
– Accounting – keep track of which users use how many and which kinds of
computer resources for account billing or for accumulating usage statistics
– Protection – ensuring that all access to system resources is controlled,
(extends to defending I/O devices/ modems/network adapters etc)
Operating System Interface
• On systems with multiple Command Interfaces,
the interpreters are known as shells
• E.g. MS-DOS
• Two ways in which commands can be executed
 Direct commands
 Files
 Uses the command to identify a file to be loaded
 Addition of new commands to system by creating
with name
 GUI- can invoke a program by clicking on mouse
System Calls
 System calls are ENTRY POINTS to OS:




Written in assembly language, C, C++
Concept developed during Dual Mode Operation
E.g. Copy of data from one file to another
Application Programming Interface: Application developers design programs
according to API’s (Specifies a set of functions that are available to an application
developer, including the parameters that are passed to each function and the return
values that the programmer can expect
 Functions that make up an API invoke the actual system calls on behalf of application
programmer
 Three general methods are used to pass parameters between a running
program and the operating system:
 Pass parameters in registers.
 Store the parameters in a table in memory, and the table address is passed as a
parameter in a register (used in Linux)
 Push (store) the parameters onto the stack by the program, and pop off the stack by
OS.
 Last two options do not limit the number or length of parameters passed
Passing of Parameters in
Register
Application Programming Interface
• OS free the application developers from having to
deal with the messy details of manipulating
computer hardware to manage memory, perform I/O
deal with command lines……
• OS provides a series of API calls which programmers
use to accomplish detailed hardware operations
• API provides the system calls by which a user
program instructs the OS to do the work
Example of System Call
 A system call is used to complete a specific task:
 Copy of data from one file to another
 Reading input file name
 Opening a file
 Error message if any
 Abnormal termination
 Deletion of a file
 Prompting a message
 Reading data for the file
 Writing data to the file or console
 Closing the file
 Normal termination
Types of System Calls
 Process control




End, Abort
Load, Execute
Create process, Terminate process
Allocate memory, Free memory
 File management
 Create file, Delete file
 Open, Close
 Read, Write, Reposition
 Device management
 Request device, Release device
 Read, Write, Reposition
 Logically attach devices, Logically detach devices
Types of System Calls
 Information maintenance
 Get time or date, Set time or date
 Communications
 Create
communication connection,
connection
 Send messages, Receive messages
Delete
communication
MS-DOS Execution
At System Start-up
Running a Program
UNIX Running Multiple Programs
Communication Models
• Communication may take place using either message
passing or shared memory.
Message Passing
Shared Memory
System Programs
 System programs are user interfaces to system calls and provide a
convenient environment for program development and execution.
Categories of system programs are : File Manipulation – used for creating, deleting, renaming, printing, dumping,






listing, and generally manipulating files and directories.
Status Information – ask the system for date, time, available memory/disk,
used memory/disk, number of users etc.
File Modification – text editors to create and modify the content of files
stored on disk or tape.
Programming Language Support – compilers, assemblers, and interpreters
for common programming languages are provided to the user with the OS.
Program Loading and Execution – OS may provide loaders and debuggers
for program loading and execution.
Communications – provide mechanism for creating virtual connections
among processes, users, and different computer systems which allows
message passing, browse web pages, send e-mail messages, log-in
remotely, transfer files from one machine to another.
Application Programs or System Utilities – many OSs are supplied with
system utilities or application programs (i.e. web browsers, word processors,
text formatters, spreadsheets, database systems) to perform common
operations.
System Programs
 Most users’ view of the operation system is defined by system programs,
not by the actual system calls.
 Command-interpreter is the most important system program and can be
implemented in two ways: Schemes of commands implementation are:
 Command interpreter itself contains the code to execute the commands,
jumps to a section of its code that sets up the parameters, and makes the
appropriate system call.
 Advantages: faster execution; easy to use by the programmers.
 Disadvantages: bigger size of the command-interpreter; needs
changes for new commands.
 All commands are implemented through special system programs.
Command file is loaded in the memory and executed.
 Advantages : small size of command interpreter; not changed for
new commands, new commands can be incorporated easily.
 Disadvantages : clumsy task of passing parameters from the
command-interpreter to the system program; slower in loading and
execution
Operating System Design
• For designing an OS, you must define certain
goals
• User Goals- (convenient to use, easy to learn
and fast)
• Designer/system goals- (easy to maintain,
flexible, efficient, error-free)
Mechanism and Policy
• Mechanism- How to do something
• Policy-what should be done
• E.g. How to distribute CPU time among multiple
processes?
• Mechanism- To use a timer, set a fixed amount of time for
a process
• Policy- how much time should be set
• If we fix a time for every process, lets say 15 sec, then it’s
hard policy
• Leave the policy to the user
Implementation
• In 1960/1970, in most Operating systems, majority of
code was written in assembly.
• Linux & Windows XP written in C, although small
sections were written in assembly
• Advantages of writing in high-level language:
• Easy to code
• Easy to maintain
• Portable
OS Structure
•
•
•
•
•
•
Simple structure (No structure) (Monolithic)
Layered Approach
Microkernels
Hybrid
Modular
Virtual Machines
Simple System Structure
(MS-DOS)
 MS-DOS was written to provide the most functionality in the





least space.
It was not divided into modules.
Monolithic (all functions in one unit)
One big box
Everything inside it
Every component can TALK to one another
No concept of User/Kernel Mode
UNIX System Structure
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.
Taking different pieces of OS and arranging them in layers
Everything nicely separated
Conceptually clean and very modular
Well-defined boundaries, swapping layers
Layered Approach
 Advantages:
modularization makes debugging and
verification much easier; design and implementation is
simplified
 Disadvantages: level definition and implementation is
very difficult; order of levels for the design of layered
structure is problematical; interaction between layers and
passing of parameters / data is very complex; less efficient
as a system call takes longer time for execution than a
non-layered system, Communication overhead
 Examples: Technische Hogeschool Eindhoven (THE) OS
and Venus layer structure.
Level 5: User programs
Level 4: buffering for input and output devices
Level 3: operator-console device driver
Level 2: memory management
Figure : THE layer structure
Level 1: CPU scheduling
Level 0: hardware
Level 6: User programs
Level 5: device drivers and schedulers
Level 4: virtual memory
Level 3: I/O channel
Level 2: CPU scheduling
Level 1: instruction interpreter
Level 0: hardware
Figure : Venus layer structure
Microkernel System Structure





Larger kernels need more space and are difficult to manage.
Contains only those components which are actually needed to run machine
Why want to keep kernel micro?
Motivation: NO SYSTEM CRASH
A bug in audio driver will cause the sound to be stop but will not crash the
computer
 Microkernel approach moves all non-essential components from the kernel
and implements them as system-level programs and user-level programs,
moving as much from the kernel into “user” space.
 Microkernel provides minimal process, memory management and
communication facility.
 Benefits:

easier to extend a microkernel

fewer changes required in the modification of microkernel

easier to port the operating system to new architectures

more reliable (less code is running in kernel mode)

more secure – if a routine fails, the rest of the OS remains untouched
Microkernel
• Disadvantages: Frequent switching
• We want efficiency of Monolithic with
Reliability of microkernel
• Hybrid Approach- MAC OS Kernel
Modular Approach
• Less code: Less bugs
• Make small modules and load them
dynamically
• Can be loaded and unloaded at run time
• Compile alongside the kernel
• Once your essential part of OS is loaded, then
it began to load modules
Modular Approach
• Crash prevention
• E.g. device drivers
• Any module can call any other module
without invoking message passing facility
• Trading off security of kernel with efficiency
Virtual Machine
• Emulation of underlying hardware
• The resources of the physical computer are shared to
create the virtual machines
• Abstract the hardware of single computer (CPU, memory,
disk drives, network interface cards etc) into different
environments
• Allow you to experiment with another operating system
without leaving your current operating system
Virtual Machine
• E.g. A virtual machine also gives you a way to run
another operating system’s software. So, if you’re a
Linux user, you can install Windows in a virtual
machine and run Windows desktop programs in that
virtual machine. Mac users can also use virtual
machines to run Windows software.
• A virtual machine can be a good place to rest out
programs you don’t trust and see what they do.
Advantages of Virtual Machine
• Share the same resources (hardware) and running
different environments
• Difficult to implement (providing an exact copy of
underlying hardware)
• No need to take out the current OS, but simply install
VM. (then test and develop)
• Programs cannot distinguish between execution on
real or virtual hardware
System Models
Chapter 3 (Processes)
Summary of previous concepts:
• A computer consists of a collection of hardware
resources, such as the processor, main memory,
I/O modules, timers, disk drives, and so on.
• Computer applications are developed to perform
some task. Typically, they accept input from the
outside world, perform some processing, and
generate output.
• Software is needed to manage the sharing of the
processor and other resources by multiple
applications at the same time.
Chapter 3
Today’s Agenda
• Review of previous concepts
• Processes Concept (Introduction)
• Discussion on Process features (scheduling,
creation, termination and communication)
• Communication in client-server systems
• When multiple applications are active at the same time, it
is necessary to protect the data, I/O use, and other
resource use of each application from the others.
• The OS was developed to provide a convenient, featurerich, secure, and consistent interface for applications to
use. The OS is a layer of software between the
applications and the computer hardware that supports
applications
Process Concept
• A process is a program in execution
• A process is an active entity
• An operating system executes a variety of programs:
– Batch system – jobs
– Time-shared systems – user programs or tasks
• OS books uses the terms job and process almost
interchangeably.
• Concurrent processing increases system performance
• A process includes:
– program counter (current activity/ address of the next instruction in the
program to be executed.
– Text section (program code)
– Stack (contains temporary data such as function parameters, return
addresses, and local variables)
– data section (contains global variables)
Program VS Process
• We emphasize that a program by itself is not a process; a
program is a passive entity, such as a file containing a list
of instructions stored on disk (often called an executable
file), whereas a process is an active entity, with a
program counter specifying the next instruction to
execute and a set of associated resources. A program
becomes a process when an executable file is loaded into
memory.
• Two common techniques for loading executable files are
double-clicking an icon representing the executable file
and entering the name of the executable file on the
command line (as in prog. exe or a. out.)
Process State
• As a process executes, it changes state:
–
–
–
–
New
: The process is being created
Ready : (ready to be allocated CPU, residing in main memory)
running: Instructions are being executed (actually using the CPU)
Waiting: The process is waiting for some external event to occur
or waiting for an input that is not yet available
– terminated: The process has finished execution
Process Attributes
What are process attributes and why is it necessary to associate
certain attributes with a process ?
Identification…. ?
If a processor is executing only one program, then NO
ALL JOY…
If I have only one CPU in my system, then how I cheat or
give an illusion of multiple things ‘going on’ ?
Time-sharing systems and multiprogramming
systems
processor is able to service multiple programs
Process Control Block
• Attributes should include ‘everything a process cares
about’ !
 Process State- (running, ready etc)
 Program Counter- (address of the next instruction in the
program to be executed)
 CPU registers (State of CPU registers- Data present in
registers in processor while the process is executing)
 CPU scheduling priority- (priority relative to other
processes, information about scheduling queues)
 Memory Management Information (location of
process’s data and instructions in memory, value of
base and limit registers)
 Accounting Information (includes amount of
processor time used, process number)
 I/O status information (data that determines the
resources this process can access such as list of I/O
devices, files etc)