Multiprogramming in Operating System



The multiprogramming operating system was introduced to overcome the limitations of batch processing operating systems in the early 1960s. The main drawback of batch systems was that the CPU remained idle during I/O operations of a job. But with multiprogramming, the CPU can execute another job while one job is waiting for I/O operations to complete.

Read this chapter to learn more about multiprogramming operating systems, its working, advantages, disadvantages, and examples.

What is Multiprogramming?

Multiprogramming is a method of running multiple programs on a single processor in such a way that the CPU is always busy. Meaning, multiple jobs are kept in the main memory, and the CPU is allocated to them one at a time. When one job is temporarily suspended or waiting for I/O operations, then the CPU will be allocated to another job. This way, the CPU will always have a job to execute.

The operating system that follows the multiprogramming approach is called a multiprogramming operating system Most of the modern operating systems like Windows, Linux, and macOS supports multiprogramming.

Working of Multiprogramming Operating System

The animation below shows the working of a multiprogramming operating system −

Working of Multiprogramming Operating System

In the above animation,

Step 1 − Jobs are loaded into the main memory.

Step 2 − The operating system selects a JOB A from the memory and allocates the CPU to it.

Step 3 − JOB A needed to perform I/O operations, so it is moved to the secondary storage, and the CPU is allocated to JOB B.

Step 4 − JOB B completes its execution and removed from the CPU. Now, JOB A is brought back from secondary storage to main memory, and the CPU is allocated to it.

Step 5 − This process continues until all jobs are executed.

Advantages of Multiprogramming Operating System

Some of the advantages of multiprogramming operating systems are −

  • Increased CPU Usage − Multiprogramming ensures that the CPU is always busy by allocating it to another job when one job is waiting for I/O operations.
  • Improved System Throughput − Throughput refers to the number of jobs completed in a given time period. Multiprogramming increases system throughput by executing multiple jobs concurrently.
  • Reduced Waiting Time − In a multiprogramming operating system, jobs do not have to wait for long periods to get executed. Since multiple jobs are kept in memory, the operating system can quickly allocate the CPU to a job when it is ready to execute.

Disadvantages of Multiprogramming Operating System

Some of the disadvantages of multiprogramming operating systems are −

  • Complexity Compared to batch processing operating systems, multiprogramming operating systems are more complex to design and implement. Advanced data structures and algorithms are required to manage multiple jobs in memory.
  • Memory Management Multiprogramming requires good memory management techniques to allocate and deallocate memory for multiple jobs.
  • Overhead The operating system needs to perform additional tasks like job scheduling, memory management, and context switching. This overhead can reduce the overall system performance.

Multiprogramming vs Multitasking Operating Systems

Multitasking operating systems are modern and advanced versions of multiprogramming operating systems. It supports the execution of multiple tasks or processes simultaneously by rapidly switching between them. Here are some key differences between multiprogramming and multitasking operating systems −

Aspect Multiprogramming OS Multitasking OS
Definition In multiprogramming, multiple programs are kept in memory, and the CPU is allocated to one program at a time. In multitasking, multiple tasks or processes are executed simultaneously by rapidly switching between them.
Focus Multiprogramming focuses on maximizing CPU utilization by keeping it busy with multiple jobs. Multitasking focuses sharing CPU time among multiple tasks to provide an illusion of simultaneous execution.
Context Switching Context switching is less frequent, happens only in the event of I/O operations or job completion. Context switching in multitasking is more frequent
Number of Cores/CPUs Works on single-core or single-CPU systems. But can be implemented on multi-core systems as well. Designed for multi-core or multi-CPU systems.
Use Case Multiprogramming is primarily used in batch processing systems. Multitasking is commonly used in modern operating systems like Windows, Linux, and macOS.

Conclusion

Multiprogramming operating systems were introduced to improve efficiency of CPU utilization in batch processing systems. It allows multiple jobs to be kept in memory, and the CPU is allocated to them one at a time. During I/O operations of one job, the CPU is allocated to another job, this way the CPU is always busy. The main advantage of multiprogramming is maximum utilization of CPU, and improved system throughput. However, it also challenges like complexity, memory management, and overhead. Most of the modern operating systems today support multiprogramming and multitasking.

Advertisements