Comprehensive Introduction to Operating Systems and Computer System Architecture

Foundations of Operating Systems

  • An Operating System (OS) functions as a program acting as an intermediary between a computer user and the computer hardware.

  • The primary goals of an Operating System include:

    • Executing user programs and simplifying the process of solving user problems.

    • Enhancing the convenience of computer system usage.

    • Utilizing computer hardware in an efficient manner.

The Operating System as a Resource Allocator and Control Program

  • The OS acts as a resource allocator that manages all system resources.

  • It is responsible for deciding between conflicting requests to ensure efficient and fair resource usage.

  • As a control program, the OS manages the execution of programs to prevent errors and improper use of the computer system.

Computer System Structure and Components

  • A computer system is divided into four distinct components:

    • Hardware: Provides the basic computing resources, including the CPU, memory, and I/O devices.

    • Operating System: Controls and coordinates the use of hardware among various application programs and users.

    • Application Programs: Define the methods for using system resources to solve user computing problems. Examples include word processors, compilers, web browsers, database systems, and video games.

    • Users: Represents people, machines, or other computers interacting with the system.

  • The abstract view of these components follows a hierarchy: User → Application Programs (compilers, browsers, development kits) → Operating System → Computer Hardware (CPU, memory, I/O devices).

User Perspectives and Varied OS Roles

  • The functionality of an OS depends on the specific point of view:

    • Standard Users: Prioritize convenience, ease of use, and high performance; they generally do not focus on resource utilization.

    • Mainframe/Minicomputer Users: In a shared environment, the OS must ensure all users are satisfied while acting as a resource allocator and control program to maintain hardware efficiency.

    • Workstation Users: Have dedicated resources but frequently utilize shared resources from servers.

    • Mobile Device Users: Use devices like smartphones and tablets which are resource-poor and optimized for usability and battery life. Interfaces include touch screens and voice recognition.

    • Embedded Computer Users: Systems in automobiles or specialized devices may have little to no user interface and run without human intervention.

  • Operating Systems are found in a vast array of environments, from toasters and game machines to ships, spacecraft, TVs, and industrial control systems.

  • The origin of the OS dates back to when military computers transitioned from fixed-use to general-purpose machines, requiring resource management and program control.

Defining the Operating System

  • There is no universally accepted definition for an OS.

  • A common approximation is "Everything a vendor ships when you order an operating system."

  • Technical definitions include:

    • The Kernel: The one program running at all times on the computer.

    • System Programs: Software that ships with the OS but is not part of the kernel.

    • Application Programs: All programs not associated with the operating system itself.

    • Middleware: A set of software frameworks included in modern general-purpose and mobile OSes that provide services for application developers, such as databases, graphics, and multimedia.

Computer System Organization and Operation

  • Operation involves one or more CPUs and device controllers connected via a common bus which provides access to shared memory.

  • There is concurrent execution of CPUs and devices, which compete for memory cycles.

  • I/O devices and the CPU can execute concurrently.

  • Each device controller oversees a specific device type and possesses a local buffer.

  • Every device controller type has a specific OS device driver to manage it.

  • The CPU is responsible for moving data from/to main memory to/from local buffers.

  • I/O occurs from the device to the local buffer of the controller.

  • The device controller signals the CPU that an operation is finished by triggering an interrupt.

Interrupt Functions and Handling

  • The OS is interrupt-driven.

  • An interrupt transfers control to the interrupt service routine through the interrupt vector, which contains the addresses of all service routines.

  • The interrupt architecture must save the address of the interrupted instruction.

  • Trap (or Exception): A software-generated interrupt caused by either a user request or an error.

  • Interrupt Handling Process:

    • The OS preserves the state of the CPU by storing registers and the Program Counter.

    • The OS determines the type of interrupt that occurred.

    • Separate segments of code determine the specific action required for each interrupt type.

  • Interrupt-Driven I/O Cycle:

    • 1. Device driver initiates I/O.

    • 2. I/O controller initiates I/O.

    • 3. Input is ready, output is complete, or an error occurs, generating an interrupt signal.

    • 4. CPU (which checks for interrupts between instructions) receives the interrupt and transfers control to the handler.

    • 5. Interrupt handler processes data and returns from the interrupt.

    • 6. CPU resumes the interrupted task.

I/O Structure and Control

  • Synchronous I/O: After I/O starts, control returns to the user program only upon completion. A wait instruction idles the CPU until the next interrupt, or a wait loop is used (causing contention for memory access). Only one I/O request can be outstanding at a time.

  • Asynchronous I/O: After I/O starts, control returns to the user program immediately without waiting.

  • System Call: A request to the OS allowing the user to wait for I/O completion.

  • Device-Status Table: Contains an entry for each I/O device indicating its type, address, and state (e.g., idle, busy). The OS indexes into this table to determine status and modify entries to include interrupts.

System Startup and Storage Hierarchy

  • Bootstrap Program: Loaded at power-up or reboot. It is typically stored in ROM or EPROM and is known as firmware. It initializes all system aspects and loads the OS kernel.

  • Storage Hierarchy (Top to Bottom):

    • 1. Registers

    • 2. Cache

    • 3. Main Memory

    • 4. Solid-state disk

    • 5. Hard disk

    • 6. Optical disk

    • 7. Magnetic tapes

Core Functions of the Operating System

1. Memory Management
  • Manages primary/main memory, which is the storage area directly accessible by the CPU.

  • Programs must reside in main memory to be executed.

  • Benefits: Allows multiple programs to be present simultaneously.

  • OS Responsibilities:

    • Allocating and deallocating memory.

    • Keeping records of which parts of memory are used by which process and how much.

    • Distributing memory during multiprocessing.

    • Selecting which processes acquire memory in multiprogramming environments.

2. Processor Management and CPU Scheduling
  • A Process is every software that runs on the computer, whether in the background or foreground.

  • OS Responsibilities:

    • Determining the status of processors and processes.

    • Selecting jobs and processors.

    • Allocating/deallocating the processor to processes.

    • Deciding how/when a process uses the CPU (CPU Scheduling).

  • Scheduling Algorithms:

    • First Come First Serve (FCFS)

    • Shortest Job First (SJF)

    • Round-Robin Scheduling

    • Priority-based scheduling

  • Purpose of Scheduling:

    • Proper CPU utilization (keeping the CPU as busy as possible).

    • Ensuring every device gets fair processor time.

    • Increasing system efficiency.

3. Device Management
  • Regulates device connections using drivers.

  • OS Responsibilities:

    • Allocating and deallocating devices to processes.

    • Keeping records of devices.

    • Deciding which process can use a device and for what duration.

4. File Management
  • Manages resource allocation/de-allocation via file systems.

  • Files are stored in different directories.

  • OS Responsibilities:

    • Keeping records of file status and locations.

    • Storage management: Creating files/directories, reading/writing data, and copying contents.

    • Determining resource access permissions.

Network vs. Distributed Operating Systems

  • Network Operating System:

    • Each computer has its own independent OS.

    • Machines interact via a common communication architecture.

    • Users access independent machines.

  • Distributed Operating System:

    • A common OS is shared across a network of computers.

    • A single OS controls the entire network.

    • Machines are dependent; users access the network to share resources.

Dual-Mode Operation

  • Processors support two modes of execution distinguished by a mode bit:

    • Kernel/Protected/Supervisor/System/Monitor/Privileged Mode: Mode bit = 00.

    • User/Non-privileged Mode: Mode bit = 11.

  • The OS runs in kernel mode; user programs run in user mode.

  • Kernel Mode Capabilities:

    • Full access to the machine instruction set and direct hardware access.

    • Privileged Instructions: Setting timers, system locks, context switching, disabling interrupts, accessing I/O devices, and removing processes from memory.

  • User Mode Capabilities:

    • Limited set of machine instructions.

    • No direct hardware access (must be coordinated by the OS).

    • Non-privileged Instructions: Reading system time, reading CPU states, switching from user to kernel mode, and sending output to a printer.

System Calls and Interfaces

  • Interface: The OS provides a user interface via a "command interpreter" or a Graphical User Interface (GUI).

  • Networking: Systems connect through communication networks using specific protocols.

  • System Call Definition: Provides OS services to user programs via an Application Program Interface (API). They are entry points to the kernel; all programs requiring resources must use them.

  • System Call Service Categories:

    • Process creation and management

    • Main memory management

    • File, directory, and file system management

    • Device handling (I/O)

    • Protection and Networking

Comparison of System Calls (Windows vs. Unix)

Category

Windows

Unix

Process Control

CreateProcess(), ExitProcess(), WaitForSingleObject()

fork(), exit(), wait()

File Manipulation

CreateFile(), ReadFile(), WriteFile(), CloseHandle()

open(), read(), write(), close()

Device Manipulation

SetConsoleMode(), ReadConsole(), WriteConsole()

ioctl(), read(), write()

Information Maintenance

GetCurrentProcessID(), SetTimer(), Sleep()

getpid(), alarm(), sleep()

Communication

CreatePipe(), CreateFileMapping(), MapViewOfFile()

pipe(), shmget(), mmap()

Protection

SetFileSecurity(), InitializeSecurityDescriptor(), SetSecurityDescriptorGroup()

chmod(), umask(), chown()

Differentiation: Interrupts and Traps

  • Interrupt: A hardware-generated signal that changes the execution flow. Handled by an interrupt handler. Used for signaling I/O completion (e.g., clock interrupts, I/O interrupts, memory faults).

  • Trap: A software-generated signal used either to call OS routines or to catch arithmetic errors.