Syllabus   Blank Homework   Quizzes  
Notes   Labs   Scores   Blank

Lecture Notes
Dr. Tong Lai Yu, 2010

  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. The Von Neumann Architecture of Computer Systems

  2. MAR -- Memory Address Register
  3. MDR -- Memory Data Register
  4. ALU -- Arithmetic Logic Unit
  5. CU -- Control Unit
  6. CPU -- Central Processing Unit = ALU + CU + Registers + some cache
  7. I/O -- Input/Output Unit
  8. MU -- Memory Unit
  9. Von Neumann Computer = CU + ALU + MU + I/O unit


  10. First Programmable Electronic Digital Computer
    Built in 1943 at Bletchley Park in U.K. to help break codes in WWII
    Need 3 weeks to 'reprogram' (rewire)

  11. What is an operating system?

    Before 1950, computers had little software, no library
    1954 MIT's first OS running on Whirlwind

    OS ~ government

  12. resource allocation
  13. provides run-time environment
  14. primary goal is convenience of operation
  15. secondary goal is efficiency of operation
  16. a virtual machine -- it hides complicated and often heterogeneous hardware from the application and provide higher level abstraction to them
  17. Easier to define an OS what they do than what they are

    Types

  18. Single job system ( e.g. DOS, CP/M )

  19. Multiprogramming system
      job scheduling
      job 1    
      job 2
      job 3
    In the 1960s, a user submitted a job ( on punched cards ) to an operator;
    Batch ~ group jobs with similar requirement together
    A job access I/O, schedule another one to run
    waited for hours or days; a small error like missing a comma would "bomb" the job

  20. Time-sharing ( multitasking )
    • a variant of multiprogramming
    • each user has an on-line terminal
    • supports simultaneous interactive users
    • Multics (multiplexed information and computing services) ~ started in 1964 as a joint project of MIT, GE, and Bell Labs
    •  

  21. Parallel system
    • multiprocessing -- has more than one CPU
    • tightly coupled
    •  
      Cray2: World's fastest from 1985-1989.

  22. Distributed systems
    • machines connected by network
    • loosely coupled
    • share resources
    • often use client-server model

  23. Clustered Systems
    • composed of two or more individual systems coupled together
    • provide high-availability service
    • loosely coupled, has load balancing
    • work as if they are a single machine
    • most top 500 supercomputers ( http://www.top500.org/ ) are clusters
      and built with Linux (98.8% in Nov 2015)
    •  
      A Beowulf cluster

  24. Real-time systems
    • fast response
    • used in military, labs

  25. 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
    • See for example, http://www.uclinux.org/,
      http://www.android.com/
  26. Operating System Concepts

  27. 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
    • think about a timesharing system

    MS-DOS

      single-task
      before loading a process   after loaded a process
      free
      memory
      command
      interpreter
      kernel
       
      free
      memory
      process
      command
      interpreter
      kernel

      Command interpreter ( or shell ) -- reads commands from a terminal

      TSR ( Terminate and Stay Resident )

    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

  28. 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 
     

  29. Shell

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

      cat file1 file2 file3 | sort -n -k 5 > /dev/lp

    • a stripped-down shell:
        	while ( 1 ) {                 //repeat forever
          	  type_prompt();              //display prompt on screen
          	  read_command ( command, parameters ); // read input from terminal
          	  if ( fork() != 0 )          // parent
            	    wait ( NULL );            //wait for child
          	  else{
            	    execve ( commamd, parameters, 0 ); // execute command
          	  }
        	}

    • Distinguish between $./prog (start a new shell) and $. ./prog (execute in current shell) (Demo: foo.sh)

  30. System Calls

    Provide the interface between a process and the operating system

  31. System calls are expensive
  32. System calls are system dependent
  33. 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.
    • 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

  34. An example of creating processes fork_demo.cpp

  35. 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.

      kernel 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 shown 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

  36. Virtual Machines

    • Further extend layered structures

    • IBM OS/360, spent 50 million dollars but abondened later (batch system, later changed to time sharing, in 1960s, TSS/360)
      Later using VM concept: successful

    • IBM VM/370 (released in 1972), virtual machine concept (except that each VM is an exact copy of the bare hardware )
      CMS (Conversational Monitor System) handles interactive timesharing users

    • 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 )

      Non-virtual
      machine
      Processes

      kernel

      hardware
       
      Virtual machine

      processes  
      processes
       
       
      processes
      kernel
      kernel
      kernel
      VM1
      VM2
      VM3
      Virtual-machine
      implementation
      hardware

    • Difficult to implement e.g. machine has 3 disks but wants to support 7 virtual machines
      resolve by providing virtual disks which are identical in all respects except size

    • Later, the idea was used in Windows to run MS-DOS

    • Virtual PC ( by MS ) can run MS Windows in Mac OS X; Apple has Boot Camp Dual Boot

      Virtualization Programs allow users to run Linux, MS Windows, along side with MAC OS X; conduct exmperiments on new OS

  37. Client-Server Model

    • kernel -- 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.

  38. Modules

  39. Java

    • Objected-oriented, architectural, distributed, multithreaded programming language

    • 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

      Java Runtime Environment (JRE)

      Java API Classes
      Java Virtual Machine

               
      Operating Systems (Unix, Windows, Mac OS/X, etc.)
               
      Hardware (Intel, ARM, Alpha, Motorola, etc)
  40. Class Exercises

    1. Operating systems manage only hardware. True or false?
    2. What is the primary goal of an OS?
    3. What limited the size and capabilities of programs in the 1950s?
    4. What is the difference between a purely layered architecture and a microkernel architecture?
    5. How do microkernels promote portability?
    6. What is the output of the following?
      int main()
      {
        int i;
                                                                                                              
        for ( i = 0; i < 3; ++i ) {
          fork();
          cout << i << endl;
        }
        return 0;
      }