Document Sample
PPT Powered By Docstoc
					   Chapter 2: Operating-System
• Operating system design
• Interface provided to users & programmers
  – System calls (programmer access)
  – User level access to system
• Services

            System Structure
• Layered approach
  – Operating system divided into layers
  – Higher levels use only services of lower levels
  – Basic principle of abstract data types (classes)

                           Figure 2.14                 2
      Original Unix O/S:
       Kernel Approach

Figure 2.13, p. 71   “monolithic structure”   3
        Monolithic “Structure”
• “an enormous amount of functionality …
  combined into one level [of abstraction in
  software]” (p. 71, Our text-- Silberschatz et al.)
• “… this approach might well be subtitled „The Big
  Mess.‟ The structure is that there is no structure.
  The operating system is written as a collection of
  procedures, each of which can call any of the other
  ones whenever it wants to.” (p. 56, Tanenbaum,
  2001, Modern Operating Systems, 2nd Ed).

         Microkernel Approach
• More like a client-server system
• Kernel supports efficient message passing
   – Plus some other low-level services such as interrupt
     handling, loading device drivers
• Much of former kernel runs in user mode (not
  kernel mode)
   – E.g., file system (server) may run in user mode
• Mach (some versions), and QNX
  (http://www.qnx.com/) operating systems
  organized this way
• QNX is real-time; small (micro) kernel can be
  advantageous to real-time systems
Mac OS X: “Microkernel”
 Approach (not really)

       Figure 2.16        6
       Solaris: Modular approach

                                                      Fig 2.15

• “Perhaps the best current methodology for
  operating-system design involves using object-
  oriented programming techniques to create a
  modular kernel” (p. 74)
• modules are typically dynamically loadable (e.g.,      7
  Solaris, Linux, Mac OS X)
 Process Interfaces to the System
• In what we‟ve been talking about so far, a
  process can either execute machine
  language code or it can make system calls
• What other kinds of process interfaces are
• API or library interfaces; e.g., POSIX
• Virtual machine interface

              Virtual Machines
• Processes provided with an interface virtually
  identical to the bare hardware
• Each process is provided with a (virtual) copy of
  the underlying computer
• E.g., IBM VM mainframe operating system
• Devices are an issue
   – e.g., Disks must be partitioned
• Each user runs an operating system on their own
  virtual machine
   – Some instructions may run directly on hardware
   – Some instructions (e.g., I/O) are interpreted
Figure 2.17: System Models

Non-virtual Machine   Virtual Machine
• “VirtualBox allows software in the virtual machine to run directly on the
    processor of the host, but an array of complex techniques is employed to
    intercept operations that would interfere with your host.
• Whenever the guest attempts to do something that could be harmful to
  your computer and its data, VirtualBox steps in and takes action.

•    In particular, for lots of hardware that the guest believes to be
    accessing, VirtualBox simulates a certain "virtual" environment
    according to how you have configured a virtual machine. For example,
    when the guest attempts to access a hard disk, VirtualBox redirects
    these requests to whatever you have configured to be the virtual
    machine's virtual hard disk -- normally, an image file on your host.”
    Java Virtual Machine (JVM)
• Specification for an abstract computer
   – http://java.sun.com/docs/books/jvms/
   – http://java.sun.com/docs/books/jvms/second_edition/html/VMSpecTOC.doc.html

• Instructions specified as “bytecode”s
• Architecture neutral
• Java program code is compiled (javac) into files
  containing bytecode
• JVM includes
   – Class loader
   – Bytecode verifier
   – Bytecode interpreter
         Mechanism vs. Policy
• Mechanisms determine how to do something
   – Provided by the operating system
   – E.g., ability to set the priority of a user process
• Policies determine what will be done
   – E.g., determining which processes get highest priority
• Separation gives flexibility
• Solaris example p. 69
   – CPU scheduling controlled by loadable tables
   – These tables provide a general purpose mechanism for
   – The policy is determined by the specific table loaded
   – E.g., different tables can provide time-sharing, batch
     processing or real-time scheduling
•   User interface
•   Program execution: Processes
•   Resource allocation
•   I/O operations
•   File-system manipulation
•   Communications
•   Protection & security
•   Error detection
•   Accounting                   Figure 2.1, p. 50 of text

                   Services - 1
• User Interface
   – GUI and command line are the most common for
     general purpose operating systems
• Program execution
   – System must be able to load a machine language
     program into RAM memory and run that program
   – Why machine language?
• Resource allocation
   – Multiple processes or users: Need to share, allocate,
     and manage resources
   – Examples of types of resources: CPU cycles (time),
     main memory, disk files, I/O devices (printers, USB
     flash drives etc).                                      15
                Services - 2
• I/O operations
  – All I/O that a program does is typically carried
    out by the O/S
  – This is for efficiency and protection
• File-system manipulation
  – “Obviously, programs [in some operating
    systems] need to read and write files and
    directories” (p. 50)
• Communications
  – Between processes on the same computer and
    between processes across different computers
  – e.g., Shared memory & message passing              16
                      Services - 3
• Protection & security
   – In multiuser systems, some people want to control access to
     their information
   – Generally, “when several separate processes execute
     concurrently, it should not be possible for one process to
     interfere with others or with the operating system itself” (p. 51)
• Error detection
   – “The operating system needs be constantly aware of possible
     errors” (p. 51)
   – Hardware errors include: power, memory, device errors
   – Software errors include: divide by 0, access of an illegal
     memory location
• Accounting
   – Which processes/users use which resources and for how long?
   – For statistics or for billing                          17
 What is a system call?
• A means for application programs to access
  operating system kernel functionality
• Types of calls
   –   Process control: E.g., create, load, execute
   –   File operations: E.g., create, open, read, write
   –   Device manipulation: E.g., request, read, write
   –   Information: E.g., get or set process attributes
   –   Communications: E.g., create connection, send or
       receive message

Figure 1.10: Transition from User
to Kernel Mode
     System Call Implementation
• For example?
   – E.g., file open, close, read or write
① Software interrupt CPU instruction is executed
② Execution control passes to an interrupt service routine in
  O/S; context switch is required
③ CPU mode bit is set to monitor (kernel) mode
④ Parameters of the software interrupt
   • Indicate the type of system call (e.g., read or write)
   • Parameters to the system call passed in registers, in a block of data,
     or the user stack
⑤ System call is executed
   • E.g., kernel code runs
   • Process is executing kernel code for duration of system call
⑥ Process is resumed (return from interrupt), back in user
  mode; context switch is required                                        20
Procedure Calls vs. System Calls

  Libraries                   Libraries

   User                        User
   process                     process

                       System call Return value(s)
 Procedure call is
 within the user
 process address space

             System Programs
• How does a system program differ from a system
• Aplication programs that provide system related
   – Use operating system calls to provide operating system
     related functionality
   – Run in user mode (not kernel mode)
• E.g.,
   – Network communications such as http servers
   – File management: directory listing, copying files (cp on
   – User interface                                         22

Shared By: