Difference between Multiprogramming, multitasking, multithreading and multiprocessing


Definition:

  1. Multiprogramming: Running two programs simultaneously like Notepad and chrome.
  2. Multiprocessing: Computer using more than 1 CPU at the same time.
  3. Multitasking: Tasks sharing a common resources with one machine.
  4. Multithreading: Extension of Multitasking.

Multiprogramming:

All modern computers run multiple tasks at the same time. So how does the operating system handles this situation?

Processes are kept in the waiting queue for execution, these processes are also called jobs. As the main memory is very less these are kept in the jobs pool. Now CPU selects one of these jobs using different algorithms and starts executing it. The job will keep executing until it is interrupted or goes for the I/O task.

Now it may take very long to complete that I/O task so CPU takes another job from the pool and starts executing it and this keeps going in this way CPU never sits idle.


Multiprocessing:

In this, more than one CPU is connected and the jobs are taken from the pool by each CPU which makes it faster. These multiprocessors share the computer bus, sometimes the clock, memory, and peripheral devices also.

This gives many advantages like even if one system fails others will keep working and processing larger files is easy.


Multitasking:

Executing multiple tasks at the same time like editing docs and listing to music is multitasking.

But this is not the case. Multitasking depends on sharing and context-switching. Suppose three processes are running, so what the CPU does is it changes process execution every delta time(very small almost unnoticeable by a human). We see this as multitasking but only one process is running at the instant of time.


Multithreading:

The thread is a basic unit of CPU utilization, it manages multiple requests without creating new copies of the program.

Suppose there is a server with serves some static files, so without multithreading, if multiple users make requests only one will be executed at the particular time thus others have to wait. This is costly and time-consuming, with multithreading server can create a new thread and can serve multiple requests at the same time.