Multiprogramming vs Multiprocessing vs Multitasking vs  Multithreading

Multiprogramming vs Multiprocessing vs Multitasking vs Multithreading

·

4 min read

A CS Student must be aware of all the above terms. Let us have a clear explanation and clean difference between all of them.

Multiprogramming

So what is this multiprogramming ?. As the name says, Multiple programmes will get executed. So, let's understand this with example.

Consider 4 programmes say P1,P2,P3,P4 are in the main memory and need the CPU to get processed. Let us get this through a conversation

CPU : Come on P1,I will execute you .
( P1 executes for sometime and need to access I/O )
P1 : Hey CPU, I need I/O.
CPU : Okay go for it. Come on P2 , Now I will execute you.
( P1 returns to CPU after its I/O completion ).
CPU : P2 You need to wait as P1 got returned ,Again I will execute You Once if P1 gets processed or goes for I/O.

In the above, when P1 goes for I/O, CPU is idle. It will be executing the next process in the main memory i.e., P2 until P1 returns. Once P1 job is done P2 gets executed and this will go on..

The main aim of multiprogramming is to maximize the CPU utilization.

Multiprocessing

When you want to purchase a new laptop, Obviously you check the specifications of each laptop. In specifications there must be "dual-core", "octa-core", "quad-core" .Ever wondered what these cores are?

Cores are the processors. Each core can execute a process.

  • dual core - 2 cores
  • quad core - 4 cores
  • octa core - 8 cores

Let's understand this through an example.

You have a building to construct and You got only one worker. It takes much long time to build right?. What If you have 4 workers instead?. As the number of workers increases, the time to complete the work decreases.

You can compare cores to the workers. If your OS is quad-core then 4 multiple core can work at a time on a single programme if and only if the programme needs 4 cores. If the programme needs only two cores then other two cores will be idle.

Multitasking

Okay. Let's say you want to listen to music and want to do coding simultaneously. This is achieved by multitasking. Chewing a bubble gum while walking is an example of multitasking.

Multitasking in single core OS

Do you think Your system really executes multiple programme concurrently?

Obviously No!

multitask+on+single+core_550.jpg

what your OS really does is, It executes each programme for a little amount of time and switches to another programme.

For example, Your OS executes Music for 5ns and it switches to editor in which you are coding and executes it for 5ns and again switches to music and executes for 5ns and this will go on.....This context switching between programmes is so fast that we humans get the illusion of multiple programmes executing at a time.Actually it is not!

Multitasking OS is also called time-sharing OS.

Multitasking in Multicore OS

multitask+on+multiple+cores_550.jpg

Here above you have 4 tasks to run simultaneously. we have dual-core OS and each core is assigned to two tasks. In the above first core needs to run wordprocessor and E-mail. As one core can't do two programmes it uses the concept of multitasking and runs it concurrently.

Multithreading

Threads are the main execution of a process. IN multithreading multiple threads execute a process and makes the process get executed faster.

Okay, You have opened a browser and you are surfing the web while downloading a song.

Here, One threads controls the downloading of song another thread controls the requests to the server. Other thread controls opening of new tab and these are done concurrently.

A single core OS with threads can work like dual-core.
A dual core OS with threads can work like quad-core.

That's it. If still you are unclear with the concepts, Please let me know.

Let's connect on twitter

Happy coding :)