Kinesia Online Course
Operating Systems
Kinesia LLC, 2003

  1. Introduction
  2. Processes
  3. Inter Process Communication
  4. Deadlocks
  5. Memory Management
 
  1. File Systems
  2. Protection and Security
  3. I/O Systems


The top software developers are more productive than
average software developers not by a factor of 10X or
100X or even 1000X but by 10,000X.

                                        Nathan Myhrvold

Introduction
  1. What is an operating system?

    OS ~ government

  2. resource allocation
  3. provides run-time environment
  4. primary goal is convenience of operation
  5. secondary goal is efficiency of operation
  6. a virtual machine -- it hides complicated and often heterogeneous hardware from the application and provide higher level abstraction to them
  7. easier to define an OS what they do than what they are

    types

  8. single job system ( e.g. DOS )

  9. multiprogramming system
      job scheduling
      job 1    
      job 2
      job 3

  10. time-sharing ( multitasking )
    • a variant of multiprogramming
    • each user has an on-line terminal

  11. parallel system
      multiprocessing -- has more than one CPU
      tightly coupled

  12. distributed systems
      machines connected by network
      loosely coupled
      share resources

  13. Clustered Systems
      composed of two or more individual systems coupled together
      provide high-availability service

  14. real-time systems
      fast response
      used in military, labs

  15. embedded operating system
      These operating systems are designed to be very compact and efficient, forsaking many functionalities that non-embedded computer operating systems provide and which may not be used by the specialized applications they run. They are frequently also real-time operating systems.

      used in mobile phones, intelligent toys, hand held devices

  16. Operating System Concepts

  17. Processes
      A process ( task ) is a program in execution, consisting of data, stack, registers needed

      multitasking -- allow serveral processes coexist

      process table -- stores information about each process

      each occurence of a process is called an instance

    MS-DOS

    before loading a process   after loaded a process
    free
    memory
    command
    interpreter
    kernel
     
    free
    memory
    process
    command
    interpreter
    kernel

    UNIX

    prcess D
    process C
    free memory
    process B
    command interpreter
    ( shell )
    process A
    kernel
      to start a new process, the shell executes a fork system call, loaded via exec

    exit when finished

    process tree -- parent process, child process

    I/O-bound process -- spends more time on I/O than on computation

    CPU-bound process -- more computation, infrequent I/O request

    scheduler -- a special process that controls how processor time is divided among other tasks that are currently running

    UNIX -- preemptive multitasking

    MS Windows 3.1

      non-preemptive -- cooperation between different tasks

      controlled with messages and message loops

  18. files

    directory, root directory

    file descriptor

      	0	standard input
      	1	standard output
      	2	standard error
      	
    pipes ( psuedo files ) -- for process communications


     Process A 
     
    ---------------
            Pipe
    ---------------

     Process B 
     

  19. shell

    • command interprector
    • prompts
    • for interaction between users and machine
    • redirect date > file

      cat file1 file2 file3 | sort > /dev/lp

  20. System Calls

    provide the interface between a process and the operating system

    these calls are generally available as assembly language, C, Pascal

    copy file1 file2

      involves a lot of system calls

      DOS was successful because it provides a lot of system calls

    Different types:

    • Process Management

    • Controlling processes involves starting up new processes, ending processes, forking new processes, waiting for processes, etc.
    • To the processes, a system call looks just like a function.
    • Example

      Consider a processes consisting of only two elements: a memory space (a subsection of the OS memory space) and a set of registers (including PC and stack pointer). We disallow any memory accesses for space outside this range. What we have is a fully functional program, capable of doing any type of computations as long as it is self-contained.

    • Is this processes capable of doing anything interesting at this point?
      No, its not. For a program to have any dynamism is must have access to some other resources via system calls.
    • All system calls get sent to a special set of instructions that are compiled in to all programs. First, these instructions saves the name of the system call and argument in registers. It generates a software interrupt, also called a trap, to let the OS know that there is something it needs to deal with.
    • The OS associates a record with each process, called a PCB ( process control block ), where it can save the register values and the program's memory space after an interrupt.
    • When the OS gets an interrupt from a system call, it saves the PCB somewhere.
    • system calls are used to create processes ( submit jobs ) ( by exec() )

      MS-DOS

      process A
      ( parent )
      DOS Shell
      ( COMMAND.COM )
      process B
      ( child )
      ( process A exit )

      or
      process A
      ( parent )
      process B
      ( child )
      ( process A exit )

      UNIX

    • multitasking, process may continue running while another program is executed
    • to start a new process, the shell ( command interpreter ) executes fork() system call
    • the selected program is loaded into memory via exec() and the program is then executed
    • the shell may wait for the process to finish or runs the process "in the background" ( cannot accept input from keyboard )
    • when process is done, exit() system call is invoked with 0 => success, nonzero => error
    • Signaling

      ~ software interrupt

    • signals are software mechanisms similar to hardware interrupt
    • a signal is used to inform a process asynchronously the occurence of an event
    • signals may be initiated by
      1. hardware -- e.g. arithmetic divide by 0, converted to signals
      2. kernel -- e.g. notify a process when a device is ready for I/O
      3. process -- e.g. a parent may terminate a child that has executed for too long
      4. users -- e.g. ^C to stop printing
    • UNIX ~ kill system call
    • File Management

      file system calls

    • open
    • close
    • create
    • read
    • write
    • get file attributes
      set file attributes

      some OS provide many more calls

    • Device Management

      I/O device

      files ~ virtual device

      DOS, UNIX merge file-device

    • Time Management

      time
      date

    • Communication

      network -- hostname

    • get hostid
    • open connection
    • close connection
    • share memory
    • map memory

  21. Operating System Structures

    • Simple Structure
    • e.g. MS-DOS, early UNIX, start with small, simple structure, limited hardware
    • to provide most functionality in least space
    • not divided into modules
    • interfaces and levels of functionality are not well separated

      MS-DOS

      Application Program

      resident system program

      MS-DOS device drivers



      ROM BIOS Device Drivers
      Some structure can be added to monolithic operating systems. The services, system calls, provided by the operating system are requested by putting the parameters in well-defined places, such as registers, or on the stack and then executing a special TRAP instruction known as the kernel call or supervisor call.

      This TRAP instruction switches the computer from user mode to kernel mode, and transfers control to the operating system.

      Early versions of UNIX
      System calls ( services ) provided by OS are requested by putting the parameters in a well-defined places such as registers or stacks.

      kenel call ( supervisor call ), switch from user mode to kenel mode ( supervisor mode ) and transfer control to OS

    • Layered Systems

      The monolithic system that is described above began with no structure and ended with an organised structure. That structure, can in fact be layered. This introduces a hierarchy of layers, where each layer is constructed above the one below.

      OS → hierarchy layers

      broken down into smaller pieces ( modules )

      flexible, has modularity, easier to debug, first layer can be debugged without any concern with the rest of the system

      Technische Hogeshool Eindhoven ( THE )
      by E.W. Dijkstra ( 1968 ) and his students
      6 layers

      5 operator
      4 user program
      3 I/O management
      2 operator-process communication
      1 memory management
      0 allocation of CPU for processes
      and multiprogramming

      The MULTICS operating system was based on such a structure. However, MULTICS was conceptually based on a series of concentric rings as shwon below. The inner-rings have more privileges than the outer-rings.

      The Unix operating system is also a layered structure:

      less efficient

      MS-DOS → OS/2,     user cannot access hardware directly

  22. Virtual Machines

    further extend layered structures

    IBM OS/360, spent 50 million dollars but abondened later

    IBM VM/370, virtual machine concept

    by using CPU scheduling, and virtual memory techniques, an OS can create an illusion of multiple processes, each executing on its own memory and CPU ( virtual machine )

    difficult to implement

  23. Client-Server Model

    • kenel -- keep it to a minimal
    • implement most of the OS in user processes
    • client process sends requests to a server process which does work and sends back the answer
    • The model can be extended with networks
    • and adapted for use in distributed computing
      if a client communicates with a server by sending it messages, the client need not know whether the message is handled locally on its own machine, or whether it is sent across a network to a server on a remote machine. As far as the client is concerned, a request was made and an answer was returned.

  24. Java

    objected-oriented, architectural, distributed, multithreaded programming languate

    a Java program consists of one or more classes

    each class ~ architectural byte code

    runs on Java Virtual Machine ( JVM )

    JVM consists of a class loader