Operating System & Concurrency Constructs – Detailed Study Notes

Operating System Overview

  • The operating system (OS) is the most important program on any computerized device.
    • Runs the hardware, provides an execution environment for all other software.
    • Recognizes and mediates user input (mouse, keyboard, touch, voice, etc.).
    • Tracks the physical location of every file on every storage device.
    • Allocates and reclaims hardware resources (CPU time, memory, I/O bandwidth, peripherals).
    • Enforces security and prevents unauthorized access.
  • OSs occur in a wide variety of intelligent systems:
    • Desktop computers, workstations, servers, notebooks, smartphones, road-navigation units, embedded controllers, etc.
  • Host role: The OS is the host that allows all application programs to run safely on the same hardware while keeping them isolated and coordinated.

Key Terminology

  • Program — A passive set of instructions stored on disk or in memory.
  • Process — A program in execution. Has its own address space, CPU context, and system resources.
  • Race Condition — Situation where the shared outcome depends on which concurrent process/thread reaches a critical section first.
  • System Call — A direct request from a running process to the operating-system kernel for a privileged service (e.g., file I/O, creating a process, allocating memory).

Semaphores

  • Proposed by Edsger Dijkstra in 1965.
  • A semaphore is a protected integer variable used to synchronize and regulate access to shared resources.
    • Two canonical operations (classical names):
    • P() / wait — decrement; if result < 0 the caller blocks.
    • V() / signal — increment; if the result ≤ 0 a blocked process is awakened.
  • Significance:
    • Enables mutual exclusion (binary semaphore) and general resource counting (counting semaphore).
    • Eliminates busy-waiting when properly implemented inside the kernel.
    • Foundation for higher-level constructs (monitors, mutexes, condition variables).
  • Practical Implications:
    • Prevents race conditions in producer-consumer, reader-writer, dining-philosopher problems.
    • Incorrect use (e.g., forgetting a V()) can cause deadlock or starvation.

Monitors

  • Higher-level synchronization construct designed to avoid the timing errors common with raw semaphores.
  • Treated as abstract data types:
    • Encapsulate shared data and the procedures that operate on it.
    • Enforce the rule: only one process/thread may be active inside the monitor at any moment.
    • Hidden internal state; clients must call exported procedures, guaranteeing safe access.
  • Provide built-in condition variables (with wait/signal) for complex interactions.
  • Widely adopted in languages (e.g., synchronized in Java) and OS kernels.

Shell

  • The primary user interface between humans and the operating system.
    • Accepts textual or script commands, starts programs, pipes data, controls jobs.
    • Modern shells provide scripting, command history, job control, and can launch graphical programs.

Core Functions of an Operating System

  • To serve as an interface between the hardware and users/applications, an OS must perform:
    1. Program-Development Support
    • Provide a text editor, translator/assembler/compiler, and link editor.
    1. Resource Allocation
    • Identify currently running programs, evaluate memory needs, grant peripheral access, and enforce data protection requirements.
    1. Utility Services
    • Compression, sorting, merging, cataloging, library maintenance.
    1. CPU Scheduling / Work Planning
    • Decide which job runs when to maximize CPU utilization and meet policy goals.
    1. Interactive Assistance
    • Facilitate user–system communication at both hardware and software levels.

Operating-System Services (Detailed)

  • Process Management
    • Create, schedule, suspend, resume, and terminate processes.
    • Provide priorities; interactive tasks usually boosted for responsiveness.
    • Background (idle) task runs when nothing else is ready.
  • Memory Management
    • Track free vs. allocated pages/segments.
    • Decide allocation/de-allocation, swap to/from secondary storage.
    • Reclaim all memory when a process ends.
  • File & Disk Management
    • Implement native file systems: create, delete, open, close, read, write.
    • Maintain metadata (owner, permissions, timestamps).
  • Networking
    • Support TCP/IP (ubiquitous) plus vendor-specific protocols.
    • Enable resource sharing (files, printers, scanners) over LAN/WAN/Internet.
  • Security
    • Authentication, authorization, auditing, encryption.
  • Device Drivers
    • Specialized software that bridges the OS I/O subsystem ↔ physical device.
    • Handles bus protocols, buffering, interrupts, and exposes a clean API upward.

Types of Operating Systems

  • Real-Time OS (RTOS) — Meets strict timing constraints for real-world control.
  • Multi-User vs. Single-User — Allow >1 user to access the same system concurrently or not.
  • Multi-Tasking vs. Single-Tasking — Permit concurrent execution of multiple programs or only one.
  • Distributed OS — Manages a cluster of independent computers to act as a single coherent system.
  • Embedded OS — Tailored for dedicated embedded devices with limited resources.

Operating-System Structures

Simple Structure (e.g., early MS-DOS, Original UNIX)

  • Minimal layering; applications can bypass kernel services and manipulate hardware directly.
  • No user/kernel mode distinction ⇒ A faulty app can crash the entire system.

Monolithic Approach

  • Kernel is one large program; all OS services are invoked via internal function calls.
  • Device drivers are loaded into and become part of the kernel address space.
  • Pros: performance, simple call interface. Cons: poor modularity, harder maintenance.

Layered / Hierarchical Approach

  • OS divided into concentric layers (0 = hardware, highest = user interface).
  • Advantages: clear modularity, easier debugging, change isolation.
  • Challenges: deciding precise layer boundaries; potential performance overhead due to extra crossings.

Microkernels

  • Strip kernel to its minimum essentials: low-level address-space management, thread management, inter-process communication (IPC).
  • All other services (file systems, device drivers, networking) move to user mode servers.
  • Benefits: easier extension, higher reliability/security, smaller trusted computing base.
  • Main drawback: message-passing overhead ⇒ slower in some workloads.
  • Example family: Mach, Minix, L4.

Client–Server Model (General & OS Context)

  • Distributed application pattern where clients request services from servers over a network (or local IPC).
  • Servers share resources; clients initiate sessions.
  • Common examples: Email, network printing, World Wide Web.
  • In OS design, many microkernel services adopt a client–server relationship (e.g., file-server process, window-server process).

Operating-System Languages & Job Control

Job Control

  • Historical need to manage multiple jobs on batch systems → prevent deadlocks, allocate scarce resources.
  • Human operators initially handled all setup; modern OSs automate most tasks yet still expose job-control interfaces.
  • Users can:
    • Start/stop jobs, move them between foreground/background.
    • Inspect resource usage, reprioritize, or terminate misbehaving tasks.

Job Control Languages (JCL)

  • Early OSes could not perform rich resource allocation themselves.
  • Users supplied punched-card directives preceding the program deck.
    • Request memory size, tape reel numbers, device assignments, etc.
  • IBM mainframe JCL still survives.
  • Time-sharing systems evolved interactive JCL; precursor to modern shells.

Jobs, Steps & Procedures (Common to DOS & OS JCL)

  • Job = top-level unit of work.
  • Step = execution of one program within the job.
  • JOB card (first control statement):
    • Identifies the job.
    • Supplies billing/accounting info.
    • Sets overall priority.
  • Procedures (PROCs) = reusable JCL macros; inserted inline to avoid repetition.
    • May accept parameters for customization.

Command Languages (Scripts)

  • Text files containing sequences of commands that would otherwise be typed at an interactive prompt.
  • Example: Windows batch file
  REM Delete Windows temp files
  echo Deleting Windows temp files.
  cd \windows\temp
  del *.* /q
  • Example: Perl script for the same task + logging.
  • Advantages:
    • Easy to write, no compilation, tiny file size, leverage built-in OS commands.
  • Disadvantages:
    • Limited expressiveness vs. full programming languages, may execute slower, dependent on OS command set.
  • Scripts vs. Command Languages: scripts usually imply richer features (variables, flow control, libraries) while command languages may be limited to shell-exposed commands.

Graphical User Interface (GUI)

  • GUI = Graphical (vs. textual) user interface.
  • Historical evolution:
    1. Command-Line Interface (CLI) — text commands (e.g., DOS prompt).
    2. Menu-Based Interface — text menus navigated by arrow keys/mouse.
    3. GUI — windows, icons, menus, pointing devices (WIMP model).
  • Modern application frameworks provide GUI widgets as classes; developers instantiate objects and define event-handling methods.
  • Significance: Lowers cognitive load, widens accessibility, supports direct manipulation.

Connections, Implications & Real-World Relevance

  • Concurrency constructs (semaphores, monitors) remain critical in multi-core & distributed computing.
  • OS structural choices (monolithic vs. microkernel) influence security posture, maintainability, and performance.
  • Job control principles underpin today’s cloud orchestration, container scheduling, and CI/CD pipelines.
  • Command languages have evolved into powerful shells (Bash, PowerShell) and ubiquitous automation tools.
  • GUI design knowledge translates into usability engineering, crucial for consumer adoption and accessibility compliance.

Numerical & Statistical References (in LaTeX)

  • Dijkstra introduces semaphores in 1965.
  • Layer numbering: 0 = hardware, n = highest user-interface layer.
  • Job priorities often mapped onto an integer range, e.g., 0\,(\text{low}) → 255\,(\text{real-time high}) in some OSs.