Multi-programmed Batch Systems

Definition

Multi-programmed Batch System is an evolution of simple batch systems where multiple jobs are kept in main memory simultaneously. When one job waits for I/O operation, CPU switches to another job instead of remaining idle. This allows better CPU utilization and reduces wasted processing time.

Main Concept: Multiprogramming

  • Multiple programs in main memory at same time
  • CPU switches between them based on I/O requirements
  • While one program waits for I/O, another uses CPU
  • CPU remains busy almost all time
  • Improves resource utilization significantly

Key Difference from Simple Batch

Simple Batch: Only one job in memory at a time, CPU idle during I/O

Multi-programmed: Multiple jobs in memory, CPU switches between them

How System Works

Process

  1. Load Multiple Jobs - Load Job 1, 2, 3 simultaneously into memory
  2. CPU Executes Job 1 - CPU starts executing Job 1
  3. Job 1 Needs I/O - Job 1 requests disk read, stops executing
  4. CPU Switches to Job 2 - CPU saves Job 1’s state, loads Job 2
  5. Job 2 Also Needs I/O - Job 2 requests printer output
  6. CPU Switches to Job 3 - Job 3 uses CPU while 1 and 2 wait
  7. Job 1 I/O Completes - CPU can switch back to Job 1
  8. Process Continues - CPU always has work, continues until all complete

Process States

Running State

  • Currently using CPU
  • Only one job at any moment
  • Executing instructions

Ready State

  • Prepared to run
  • Waiting for CPU time
  • Can start immediately
  • Multiple jobs possible

Waiting State

  • Waiting for I/O to complete
  • Cannot use CPU until I/O done
  • Examples: disk read, printing, keyboard input

Context Switching

Switching from one job to another.

What Gets Saved

  1. Program Counter - Where execution was
  2. Registers - All CPU register values
  3. Memory Status - What data in use
  4. Process State - Current status
  5. Process Priority - Scheduling information

What Gets Restored

  1. Load new program counter
  2. Load new register values
  3. Load memory state
  4. Restore full context
  5. Resume execution

Advantages

  1. Better CPU Utilization

    • CPU rarely idle
    • While Job 1 does I/O, Job 2 uses CPU
    • Significant improvement
  2. Increased Throughput

    • More jobs per unit time
    • Example: 5 jobs/hour instead of 2
    • Much higher productivity
  3. Faster Turnaround

    • Jobs complete faster
    • Don’t wait for all previous jobs
    • Reduces total processing time
  4. Reduced Waiting

    • I/O doesn’t block other jobs
    • Other jobs continue
    • More efficient sharing
  5. Better Resource Sharing

    • Devices shared among jobs
    • More efficient use

Disadvantages

  1. Increased Complexity

    • OS design much complicated
    • Difficult to implement
    • More bugs possible
  2. Memory Requirements

    • Multiple jobs need more memory
    • Each needs own space
    • Memory becomes bottleneck
    • Less memory per job
  3. Context Switching Overhead

    • Switching takes time
    • Saving/loading not free
    • Can waste CPU time if too frequent
  4. Memory Protection Required

    • Job 1 cannot access Job 2’s memory
    • Must implement isolation
    • Complex to implement
  5. Job Interference

    • Crash of Job 1 might affect Job 2
    • Need protection
    • Debugging harder
  6. Still No User Interaction

    • Still batch-oriented
    • Not interactive
    • Users still wait

Scheduling Decisions

OS must decide:

  • Which job gets CPU next?
  • For how long?
  • When to switch?

Methods

  • FCFS - First Come First Served (simple)
  • SJF - Shortest Job First (reduces wait)
  • Priority - Assign job priorities

Real Example

Bank with 3 jobs:

  • Job A: Salary calculation (CPU-intensive)
  • Job B: Disk backup (I/O-intensive)
  • Job C: Report printing (I/O-intensive)

Timeline:

  • 0-10ms: Job A calculates
  • 10-20ms: Job B reads disk, Job C prints
  • 20-30ms: Job B resumes after I/O
  • CPU always busy!

Comparison: Batch vs. Multi-programmed

AspectBatchMulti-programmed
Jobs in Memory1Multiple
CPU IdleHighLow
ThroughputLowHigher
ComplexitySimpleComplex
Memory NeededLessMore
Context SwitchingNoYes

Important Concepts

  • Preemption - OS can take CPU from job
  • Non-preemptive - Job keeps CPU until I/O
  • I/O Bound - Lots of I/O operations
  • CPU Bound - Uses CPU continuously

Evolution

  • Improved batch systems significantly
  • Better throughput and utilization
  • But still not interactive
  • Still long wait for results
  • Led to time-sharing systems