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
- Load Multiple Jobs - Load Job 1, 2, 3 simultaneously into memory
- CPU Executes Job 1 - CPU starts executing Job 1
- Job 1 Needs I/O - Job 1 requests disk read, stops executing
- CPU Switches to Job 2 - CPU saves Job 1’s state, loads Job 2
- Job 2 Also Needs I/O - Job 2 requests printer output
- CPU Switches to Job 3 - Job 3 uses CPU while 1 and 2 wait
- Job 1 I/O Completes - CPU can switch back to Job 1
- 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
- Program Counter - Where execution was
- Registers - All CPU register values
- Memory Status - What data in use
- Process State - Current status
- Process Priority - Scheduling information
What Gets Restored
- Load new program counter
- Load new register values
- Load memory state
- Restore full context
- Resume execution
Advantages
-
Better CPU Utilization
- CPU rarely idle
- While Job 1 does I/O, Job 2 uses CPU
- Significant improvement
-
Increased Throughput
- More jobs per unit time
- Example: 5 jobs/hour instead of 2
- Much higher productivity
-
Faster Turnaround
- Jobs complete faster
- Don’t wait for all previous jobs
- Reduces total processing time
-
Reduced Waiting
- I/O doesn’t block other jobs
- Other jobs continue
- More efficient sharing
-
Better Resource Sharing
- Devices shared among jobs
- More efficient use
Disadvantages
-
Increased Complexity
- OS design much complicated
- Difficult to implement
- More bugs possible
-
Memory Requirements
- Multiple jobs need more memory
- Each needs own space
- Memory becomes bottleneck
- Less memory per job
-
Context Switching Overhead
- Switching takes time
- Saving/loading not free
- Can waste CPU time if too frequent
-
Memory Protection Required
- Job 1 cannot access Job 2’s memory
- Must implement isolation
- Complex to implement
-
Job Interference
- Crash of Job 1 might affect Job 2
- Need protection
- Debugging harder
-
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
| Aspect | Batch | Multi-programmed |
|---|---|---|
| Jobs in Memory | 1 | Multiple |
| CPU Idle | High | Low |
| Throughput | Low | Higher |
| Complexity | Simple | Complex |
| Memory Needed | Less | More |
| Context Switching | No | Yes |
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