Understanding Multiprogramming, Multiprocessing, and Multitasking in Computer Systems


Understanding Multiprogramming, Multiprocessing, and Multitasking in Computer Systems

Multiprogramming

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

Suppose we have a single processor system and we have 5 processes P1, P2, P3, P4 and P5, which are to be executed by CPU. Since CPU can execute only one process at a time, it starts with process P1 and sometime after the execution of process P1, process P1 needs some I/O operations. So, it gives up on the CPU and starts performing that I/O operation. Now, the CPU will wait for the P1 process to return for its execution and the CPU will be in an idle state for that period. But at the same time, other processes i.e. P2, P3, P4, and P5 are waiting for execution. Our CPU is in idle state and this is a very expensive thing. So, why put the CPU in an idle state? What can we do, if process P1 wants to do some I/O operations then let process P1 do I/O work and also, process P2 will be given CPU and if process P2 also needs some I/O operations, then the CPU will be given to process P3 etc. This is called context switching. Once the I/O work is done by the processes the CPU can resume the task of that process (ie process P1 and P2) and by doing so the CPU will never go to idle state. This concept of effective CPU usage is called Multiprogramming.

So, in a multiprogramming system, the CPU executes some part of a program, then some part of another program, and so on. By doing this, the CPU will never go into idle state until there is a process ready to execute at the time of context switching.

Advantages of Multiprogramming

  • Too much CPU usage as the CPU will not idle until there is no process to execute.
  • Less waiting time for processes.
  • Can be used in a multiuser system. A multiuser system allows different users of different computers to access the same CPU and as a result, multiprogramming occurs.

Disadvantages of Multiprogramming

  • Since you have to do context switching, you must have some process scheduling technique that will tell the CPU which process to take for execution and that is tricky.
  • Here, the CPU is executing some part of one process, then some part of another, etc. So, in this case, the memory will be divided into smaller parts as each process requires some memory and this will result in memory fragmentation. So, more or less continuous memory will not be available.

Multiprocessing

As we know that in a uni-processor system, the processor can execute only one process at a time. But when you have a lot of work to do in your system and a processor is small enough to do all those tasks in the required unit of time, we can use more than one processor in the same system.

So, two or more processors present in the same computer, sharing system bus, memory and other I/O is called multiprocessing system.

Suppose, we have 5 processes P1, P2, P3, P4 and P5. In 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, different processes can be assigned to different processors and this, in turn, reduces the overall process execution time by the system. A dual-processor system can execute two processes at a time whereas a quad-processor can execute four processes at a time.

Advantages of multiprocessing

  • Since more than one processor is working at a time, more work is done in less 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 work can be done with the help of other processor. This, in turn, increases reliability.
  • If you are doing a lot of work on one processor it will result in more battery drain. But if the work is split across different processors it will provide better battery efficiency.
  • Multiprocessing is an example of true parallel processing, i.e. executing more than one process at the same time.

Disadvantages of Multiprocessing

  • Since more than one processor is working at a time. So the coordination between them is very complex.
  • Since, bus, memory and I/O devices are shared. So, if one processor is using some I/O then the other processor will have to wait for its turn and this will result in a decrease in throughput.
  • For efficient operation of all processors at a time, we must have a large main memory and this, in turn, adds to the cost.

Multitasking

If CPU is allocated to a process that is taking a lot of time then other processes will have to wait for the execution of that process and consequently the processes will have to wait longer for resource allocation.

For example, if process P1 is taking 20 seconds of CPU time and CPU is allocated to P1. Now, if a process P2 comes up that requires 1 second of CPU time, then P2 has to wait for 20 seconds, even though it only needs 1 second of CPU time.

What we can do here is that we can set a time quantum and CPU will be given to each process only for that time and after that, CPU will be given to another process that is ready for execution. So, in our above example, if the scheduled time amount is 2 seconds, initially, process P1 will be allocated CPU for 2 seconds and then it will be given to process P2. The process of P2 completes its execution in 1 second and then the CPU is given to process P1 again. Since no other process is available for execution, 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 different processes is called multitasking.

Multitasking is multiprogramming with time-sharing.

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

For multitasking, first there should be multiprogramming and second, there should be time-sharing.

Advantages of Multitasking

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

Disadvantages of Multitasking

  • Each process will be given a certain amount of time in a cycle. So the process with higher priority will also have to wait.
  • If the processor is slow and the work is huge, it may not run smoothly. This requires more processing power.

Multiprogramming vs Multiprocessing vs Multitasking

We have seen the concepts of multiprogramming, multiprocessing, multitasking. Hence, when we do context switching between different processes it is called multiprogramming system. This is done for better CPU utilization and ensures that the CPU never goes into an idle state. Whereas multitasking is a process of multiprogramming with a time-sharing concept where some time is given to every process and after that time CPU is provided to other processes. On the other hand, multiprocessing is the use of more than one processor in the same system to achieve true parallel processing.

Next Post Previous Post
No Comment
Add Comment
comment url