What is an operating system (OS)?

Goals of OS

  1. Make computer convenient to use by providing a virtual/extended machine that is easier to program than the underlying hardware,
  2. Use computer equipment efficiently
Resources - processor(s), memory, timers, disks, network Resources competed for by several programs E.g., limited memory so allocation - which programs are loaded - limits access to memory used by program Can view OS as resource manager. Responsible for resource allocation, tracking resources, accounting, and mediating conflicting requests

Hardware support for Operating systems

Need protection from user programs that:

  1. access memory of other programs or the OS
  2. access files of other programs
  3. go into an infinite loop

Protection Techniques

  1. Dual-Mode Operation - two (at min.) modes of operation: user mode and monitor(/supervisor/system/privileged) mode with some privileged instructions only executable in monitor mode

    Hardware: Bit in CPU to indicate mode and check on monitor mode for privileged instr.s

    e.g., I/O instructions are privileged, so a user program must request I/O through the OS

  2. Restrict a user program to its allocated address space. In a simple computer, a user program might be allocated a single continguous address space in memory. The two special purpose CPU registers: StartMemory and EndMemory can bracket the user program's address space. All memory addresses that the user program performs can be checked by hardware in the CPU to make sure that they fall between the values in these registers. If the user program tries to access memory outside the range of addresses indicated by these registers, an interrupt/exception is raised to return control back to the operating system. (On more complex computers, a memory-management unit (MMU) provides a more sophicated address mapping scheme (paging, segmentation, paged segments, none)) Modifications to the memory-management registers are privileged.
  3. CPU Timer - OS sets a timer to expire and interrupt a user pgm before the user pgm is started

    Remember that only one program (in a single CPU system) can be executing at a time so when the OS turns control over to a user program it has "lost control."

    Modifications to the CPU timer are privileged

OS maintained queues and does scheduling: I/O queues - since I/O is so slow, several programs might have outstanding requests to use an I/O device so a queue for each I/O device is necessary. Short-term (Ready) queue - programs that are in memory and ready to execute. All they need is the CPU to run. Medium-term queue - programs that are partially executed, but have been swapped out of memory to disk Long-term queue - user has requested the a program be executed, but it has not yet been loaded into memory