Multiprogramming vs Multiprocessing vs Multitasking

Whenever we are talking about processes in Operating System, then all of us must have come across three confusing terms i.e. Multiprogramming, Multiprocessing, and Multitasking. Here, in this blog, we will learn about what exactly is the meaning of these terms and what is the difference between these terms? Let's find out.

Multiprogramming

A process executing in a computer system mainly requires two things i.e. CPU time and I/O time. The CPU time is the time taken by CPU to execute a process and I/O time is the time taken by the process for I/O operations such as some file operation like read and write. Generally, our computer system wants to execute a number of processes at a time. But it is not possible. You can run only one process at a time in a processor. But this can result in some problems.

Suppose we have a single processor system and we have 5 processes P1, P2, P3, P4, and P5 that is to be executed by the CPU. Since the CPU can execute only one process at a time, so it starts with the process P1 and after some time of execution of process P1, the process P1 requires some I/O operation. So, it leaves the CPU and starts performing that I/O operation. Now, the CPU will wait for the process P1 to come back for its execution and the CPU will be in an idle state for that period of time. But at the same time, other processes i.e. P2, P3, P4, and P5 are waiting for there execution. Our CPU is in idle state and this is a very expensive thing. So, why to keep the CPU in the idle state? What we can do is, if the process P1 wants to perform some I/O operation then let the process P1 do the I/O job and at the same time, the CPU will be given to the process P2 and if the process P2 also requires some I/O operation, then the CPU will be given to process P3 and so on. This is called Context Switching. Once the I/O work is done by the processes then the CPU can resume the working of that process(i.e. the Process P1 and P2) and by doing so the CPU will never go into the idle state. This concept of effective CPU utilization is called Multiprogramming.

So, in a multiprogramming system, the CPU executes some part of one program, then some part of another program, and so on. By doing so, the CPU will never go into the idle state unless there is no process ready to execute at the time of Context Switching.

Advantages of Multiprogramming

  • Very high CPU utilization as the CPU will never be idle unless there is no process to execute.
  • Less waiting time for the processes.
  • Can be used in a Multiuser system. A Multiuser system allows different users that are on different computers to access the same CPU and this, in turn, result in Multiprogramming.

Disadvantages of Multiprogramming

  • Since you have to perform Context Switching, so you need to have some process scheduling technique that will tell the CPU which process to take for execution and it is difficult.
  • Here, CPU is executing some part of one process, then some part of other and so on. So, in this case, the memory will be divided into small parts as each process require some memory and this will result in memory fragmentation. So, no or less continuous memory will be available.

Multiprocessing

As we know that in a uni-processor system, the processor can execute only one process at a time. But when your system is having a lot of work to do and one processor is very less to perform all those work in the required unit of time, then we can use more than one processors in the same system.

So, two or more processors present in the same computer, sharing the system bus, memory, and other I/O is said to be Multiprocessing System.

Suppose, we are having 5 processes P1, P2, P3, P4, and P5. In a uni-processor system, only one process can be executed at a time and after its execution, the next process will be executed and so on. But in a multiprocessor system, the different process can be assigned to different processors and this, in turn, decreases the overall process execution time by the system. A dual-processor system can execute two processes at a time while a quad-processor can execute four processes at a time.

Advantages of Multiprocessing

  • Since more than one processors are working at a time, so more work is done in a shorter period of time. Throughput will be increased. You can read more about throughput from here.
  • We have more than one processor, so if one processor is not working then the job can be done with the help of other processors. This, in turn, increases reliability.
  • If you are providing lots of work on one processor then it will result in more battery drain. But if the work is divided into various processors then it will provide a better battery efficiency.
  • Multiprocessing is an example of true parallel processing i.e. more than one processes executing at the same time.

Disadvantages of Multiprocessing

  • As more than processors are working at a particular instant of time. So, the coordination between these is very complex.
  • Since, the buses, memory, and I/O devices are shared. So, if some processors are using some I/O then another processor has to wait for its turn and this will result in the reduction of throughput.
  • To have the efficient working of all the processors at a time, we need to have a large main memory and this, in turn, increase the cost.

Multitasking

If the CPU is allocated to such a process that is taking a lot of time then other processes will have to wait for the execution of that process and this will result in starvation.

For example, if process P1 is taking 20 seconds of CPU time and the CPU is allocated to P1. Now, if some process P2 comes that requires 1 second of CPU time, then P2 have to wait for 20 seconds irrespective of the fact that it requires only 1 second of CPU time.

What we can do here is, we can set a time quantum and CPU will be given to each process for that amount of time only and after that, the CPU will be given to some other process that is ready for execution. So, in our above example, if the decided time quantum is 2 seconds, then initially, the process P1 will be allocated the CPU for 2 seconds and then it will be given to process P2. The process P2 will complete its execution in 1 second and then the CPU will be given to process P1 again. Since there is no other process available for execution, the process P1 can continue to execute for its remaining time i.e. 18 seconds. This is called time-sharing. And the concept of time-sharing between various processes is called Multitasking.

Multitasking is Multiprogramming with time-sharing.

Here the switching between processes is so quick that it gives an illusion that all the processes are being executed at the same time.

For multitasking, firstly there should be multiprogramming and secondly, there should be time-sharing.

Advantages of Multitasking

  • Since each process is given a particular time quantum for execution. So, it will reduce starvation.
  • It provides an illusion to the user that he/she is using multiple programmes at the same time.

Disadvantages of Multitasking

  • Every process will be given a fixed time quantum in one cycle. So, the high priority process will also have to wait.
  • If the processor is slow and the work is very large, then it can't be run smoothly. It requires more processing power.

Multiprogramming vs Multiprocessing vs Multitasking

We have seen the concepts of Multiprogramming, Multiprocessing, Multitasking. So, when we do the context switching between various processes then it is called the multiprogramming system. It is done for better CPU utilization and it makes sure that the CPU never goes in the idle state. While the multitasking is a process of multiprogramming with a time-sharing concept where every process is given some time quantum and after that time quantum the CPU is then provided to other processes. On the other hand, Multiprocessing is the use of more than one processors in the same system so that true parallel processing can be achieved.

That's all from this blog.

Hope you enjoyed this blog.

Keep Learning :)

Team AfterAcademy!