Lecture 2

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 33

Chapter 2

Operating System Structures

Operating System Concepts – 7th Edition, Jan 12, 2005 1.1 Silberschatz, Galvin and Gagne ©2005
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

Operating System Concepts – 7th Edition, Jan 12, 2005 1.2 Silberschatz, Galvin and Gagne ©2005
Operating System Services

Operating System Concepts – 7th Edition, Jan 12, 2005 1.3 Silberschatz, Galvin and Gagne ©2005
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. The program must be able to end its
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.

(More on next slide)


Operating System Concepts – 7th Edition, Jan 12, 2005 1.4 Silberschatz, Galvin and Gagne ©2005
Operating System Services (Cont.)

 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 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
 Sometimes, it has no choice but to halt the system
 Or, terminate an error-causing process
 Or, return an error code to a process for the process to detect and possibly
correct

Operating System Concepts – 7th Edition, Jan 12, 2005 1.5 Silberschatz, Galvin and Gagne ©2005
Operating System Services (Cont.)
Another set of operating system services are used for ensuring the
efficient operation of the system itself via resource sharing

 Resource allocation - When multiple users or multiple jobs are 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
 Protection and security - The owners of information stored in a multi-user
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

Operating System Concepts – 7th Edition, Jan 12, 2005 1.6 Silberschatz, Galvin and Gagne ©2005
User Operating System Interface

Operating System Concepts – 7th Edition, Jan 12, 2005 1.7 Silberschatz, Galvin and Gagne ©2005
The Command Line Interface

 There are two fundamental approaches for users to interface with the
operating system: command line interface and graphical user interface
 The command line interface, or command interpreter, allows users to
directly enter commands to be performed by the operating system
 Some operating systems include the command interpreter in the kernel.
 Others, such as Windows and UNIX, treat the command interpreter as a
special program that is running when a job is initiated or when a user first logs
on
 Part of the interface is implemented in the form of a single shell program; the
other part is implemented as system programs
 The main function of the command interpreter is to get and execute the next
user-specified command

Operating System Concepts – 7th Edition, Jan 12, 2005 1.8 Silberschatz, Galvin and Gagne ©2005
The Graphical User Interface (GUI)
 A graphical user interface (GUI) provides a mouse-based interface
consisting of windows and menus
 Depending on the position of the mouse cursor, clicking on a
mouse button can invoke a program, select a file or directory, or
pull down a menu that contains commands
 Graphical user interfaces first appeared because of the research
that took place in the early 1970s at the Xerox PARC research
facility
 Many systems now include both CLI and GUI interfaces
 Microsoft Windows is GUI with CLI “command” shell
 Solaris is CLI with optional GUI interfaces

Operating System Concepts – 7th Edition, Jan 12, 2005 1.9 Silberschatz, Galvin and Gagne ©2005
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 have deep knowledge
of a system frequently use the command-line interface.
 For them, it is more efficient, giving them faster access to the activities
they need to perform.
 In contrast, most Windows users are happy to use the Windows GUI
environment and almost never use the MS-DOS shell interface.
 The user interface can vary from system to system and even from user
to user within a system

Operating System Concepts – 7th Edition, Jan 12, 2005 1.10 Silberschatz, Galvin and Gagne ©2005
System Calls

Operating System Concepts – 7th Edition, Jan 12, 2005 1.11 Silberschatz, Galvin and Gagne ©2005
System Calls
 Systems calls provide an interface to the services made available by an
OS
 These calls are generally available as routines written in a high-level
language (C or C++)
 Certain low-level tasks (for example, tasks where hardware must be
accessed directly) may have to be written using assembly-language
instructions
 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)
 Java API for the Java virtual machine (JVM)

*POSIX – Portable Operating System Interface

Operating System Concepts – 7th Edition, Jan 12, 2005 1.12 Silberschatz, Galvin and Gagne ©2005
Example of System Calls
 Below is a sequence of system calls to copy the contents of one file
to another file

Operating System Concepts – 7th Edition, Jan 12, 2005 1.13 Silberschatz, Galvin and Gagne ©2005
System Call Implementation
 Typically, there is 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)

Operating System Concepts – 7th Edition, Jan 12, 2005 1.14 Silberschatz, Galvin and Gagne ©2005
API – System Call – OS Relationship

Operating System Concepts – 7th Edition, Jan 12, 2005 1.15 Silberschatz, Galvin and Gagne ©2005
Standard C Library Example

 C program invoking printf() library call, which calls the write() system call

Operating System Concepts – 7th Edition, Jan 12, 2005 1.16 Silberschatz, Galvin and Gagne ©2005
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

Operating System Concepts – 7th Edition, Jan 12, 2005 1.17 Silberschatz, Galvin and Gagne ©2005
Parameter Passing via Table

Operating System Concepts – 7th Edition, Jan 12, 2005 1.18 Silberschatz, Galvin and Gagne ©2005
Types of System Calls

Operating System Concepts – 7th Edition, Jan 12, 2005 1.19 Silberschatz, Galvin and Gagne ©2005
Five Major Categories
 System calls can be grouped into five major categories:
 Process control
 Load, execute, end, abort, create process, get/set process
attributes, wait for time/signal, allocate/free memory
 File management (manipulation)
 Create/delete/open/close/read/write a file, get/set file attributes
 Device management
 Request/release device, read/write data, get/set attributes
 Information maintenance
 Get/set time or date, get/set system data, get/set attributes for
process/file/device
 Communications
 Create/delete connection, send/receive messages, attach/detach
devices

Operating System Concepts – 7th Edition, Jan 12, 2005 1.20 Silberschatz, Galvin and Gagne ©2005
Example of MS-DOS execution

(a) At system startup (b) running a program

Operating System Concepts – 7th Edition, Jan 12, 2005 1.21 Silberschatz, Galvin and Gagne ©2005
Example of LINUX Running Multiple Programs

Operating System Concepts – 7th Edition, Jan 12, 2005 1.22 Silberschatz, Galvin and Gagne ©2005
System Programs

Operating System Concepts – 7th Edition, Jan 12, 2005 1.23 Silberschatz, Galvin and Gagne ©2005
System Program Categories

 System programs provide a convenient environment for program


development and execution. They can be divided into:
 File management (create, delete, copy, rename, print, list, etc.)
 Status information (date, time, memory, disk space, users, etc.)
 File modification (text editors, file search)
 Programming language support (compiler, linkers, interpreters)
 Program loading and execution (loaders) Once a program is assembled
or compiled, it must be loaded into memory to be executed
 Communications (virtual links, send/receive messages)
 Application programs (web browsers, office suites)
 Most users’ view of the operation system is defined by system
programs, not the actual system calls
 System programs provide a convenient environment for program
development and execution
 Some of them are simply user interfaces to system calls; others are
considerably more complex

Operating System Concepts – 7th Edition, Jan 12, 2005 1.24 Silberschatz, Galvin and Gagne ©2005
Operating System Design and
Implementation

Operating System Concepts – 7th Edition, Jan 12, 2005 1.25 Silberschatz, Galvin and Gagne ©2005
Operating System Design and Implementation

 The first problem in designing a system is to define goals and


specifications.
 At the highest level, the design of the system will be affected by the
choice of hardware and the type of system: batch, time sharing,
single user, multiuser, distributed, real time, or general purpose
 Beyond this highest design level, the requirements may be much
harder to specify. The requirements can, however, be divided into
two basic groups:
 User goals – operating system should be convenient to use,
easy to learn, reliable, safe, and fast
 System goals – operating system should be easy to design,
implement, and maintain, as well as flexible, reliable, error-free,
and efficient

Operating System Concepts – 7th Edition, Jan 12, 2005 1.26 Silberschatz, Galvin and Gagne ©2005
Operating System Design and Implementation (Cont.)
Mechanisms and Policies
 One important principle is the separation of policy from mechanism.
 Mechanisms determine how to do something; policies determine
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.
 The separation of policy and mechanism is important for flexibility.
 Policies are likely to change across places or over time.
 In the worst case, each change in policy would require a change in the
underlying mechanism.
 A general mechanism insensitive to changes in policy would be more
desirable.
 A change in policy would then require redefinition of only certain
parameters of the system.

Operating System Concepts – 7th Edition, Jan 12, 2005 1.27 Silberschatz, Galvin and Gagne ©2005
Operating System Structure

Operating System Concepts – 7th Edition, Jan 12, 2005 1.28 Silberschatz, Galvin and Gagne ©2005
29

Monolithic Architecture

 Monolithic operating system


 Every component contained in kernel
 Any component can directly communicate
with any other
 Tend to be highly efficient
 Disadvantage is difficulty determining
source of subtle errors

Operating System Concepts – 7th Edition, Jan 12, 2005 1.29 Silberschatz, Galvin and Gagne ©2005
30

Layered Architecture

 Layered approach to operating systems


 Tries to improve on monolithic kernel
designs
 Groups components that perform similar
functions into layers

Operating System Concepts – 7th Edition, Jan 12, 2005 1.30 Silberschatz, Galvin and Gagne ©2005
Layered Approach …

 In a 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.
 Tries to improve on monolithic kernel designs
 Groups components that perform similar functions into
layers
 The main advantage of the layered approach is simplicity of
construction and debugging.
 The layers are selected so that each uses functions
(operations) and services of only lower-level layers.
 The first layer can be debugged without any concern for the
rest of the system, because, by definition, it uses only the
basic hardware (which is assumed correct) to implement its
functions.
Operating System Concepts – 7th Edition, Jan 12, 2005 1.31 Silberschatz, Galvin and Gagne ©2005
Layered Operating System

Operating System Concepts – 7th Edition, Jan 12, 2005 1.32 Silberschatz, Galvin and Gagne ©2005
End of Introduction

Operating System Concepts – 7th Edition, Jan 12, 2005 1.33 Silberschatz, Galvin and Gagne ©2005

You might also like