Table of contents
1.
Introduction
2.
What is Multitasking in OS?
2.1.
Single-tasking OS
2.2.
Multitasking OS
3.
Types of Multitasking
4.
Process and Thread
5.
Process-based and Thread-based Multitasking
5.1.
Process-based Multitasking
5.2.
Thread-based Multitasking
6.
Differences between Process-based Vs Thread-based Multitasking 
7.
Frequently Asked Questions. 
7.1.
What is preemption?
7.2.
What is a single-user operating system?
7.3.
What is a multi-user operating system?
7.4.
Name some scheduling algorithms that are based on preemptive scheduling.
8.
Conclusion
Last Updated: Mar 27, 2024

Process-based and Thread-based Multitasking

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?
Operating System

Introduction

OS(Operating System) is one the most asked topic in interviews. So if you are preparing for interviews, it’s essential to be clear with specific critical topics. One such vital topic is Threads in OS. 

This blog will discuss everything you need to know to get started with multitasking in OS.

Also see, Thread and its Types, Multiprogramming vs Multitasking

What is Multitasking in OS?

According to Wikipedia,

‘In computingmultitasking is the concurrent execution of multiple tasks (also known as processes) over a certain period of time.’

OS can be divided into two broad categories based on the number of tasks it can perform at a time,

  1. Single-tasking OS
  2. Multitasking OS
     

Also, see Difference Between Multitasking and Multiprocessing and Open Source Operating System.

Single-tasking OS

  • OS allows only one program to run at a time.
  • There is no concept of multiple users, administrators, or root accounts.
  • There is no protection between the OS and user programs.
  • MS-DOS is an example of a single-tasking OS.

 

Drawbacks:

  • CPU is not utilized efficiently, as only one task will run at a time.
  • Most of the time, memory will be wasted.

Multitasking OS

  • OS allows more than one program to be running in concurrency.
  • Multitasking is achieved by time-sharing, dividing available processor time between multiple processors.
  • OS gives the illusion that multiple processes are running at the same time. But in reality, the CPU keeps switching between different processes, and as this switching occurs very fast, such an illusion is created.
  • All modern OS can handle a large number of processes simultaneously.
  • Multitasking OS yields better CPU utilization than single-tasking OS.

 

Example

Multitasking

Multitasking

In the above screenshot, we can see four tabs open in the Google Chrome browser. Microsoft Word and Visual Studio Code are also running at the same time.

Also See, procedure call in compiler design

Types of Multitasking

Multitasking can be categorized into the following two types,

  1. Cooperative multitasking
  2. Preemptive multitasking

In cooperative multitasking, if a task/process is not ready for execution, it will voluntarily give up the control of the processor so that other tasks can run. It is also known as non-preemptive multitasking. Cooperative multitasking is still used in RISC OS systems.

In the case of preemptive multitasking, if a high-priority task becomes ready for execution, it can immediately acquire the processor by preempting the execution of a lower-priority task.

It is a core feature of all Unix-like operating systems like Linux, and Solaris.

Process and Thread

A process is the instance of a program executed by one or many threads.

On the other hand, a thread is a basic CPU utilization unit. It has its own thread ID, a program counter, a register, and a stack. 

Process and Thread

The above diagram shows a process with two threads. Check this blog here to learn more about processes and threads.

Process-based and Thread-based Multitasking

Multitasking can further be divided into two types,

  1. Process-based Multitasking
  2. Thread-based Multitasking

Process-based Multitasking

In this type of multitasking, two or more processes can be run concurrently.

Features: 

  • The smallest unit of execution is a process.
  • Inter-process communication is costly and inefficient.
  • Context-switching time is more in the case of processes.
  • It is unable to gain access over CPU idle time.
  • Every program has its own address space. 
  • It requires more overhead than thread-based multitasking.

 

Example:

A browser and a video player are two processes that can be running at the same time on a modern computer.

Thread-based Multitasking

In this type of multitasking, two or more threads can be run concurrently. 

Features:

  • The smallest unit of execution is a thread.
  • Inter-thread communication is inexpensive and efficient.
  • Context-switching time is less in the case of threads.
  • It can gain access over CPU idle time.
  • Threads share the same address space.
  • It requires less overhead than process-based multitasking.

 

Example:

A word processor can simultaneously have a thread for spelling and grammar checks and another thread for responding to keystrokes from the user.

Related Article Threads in Operating System

Differences between Process-based Vs Thread-based Multitasking 

Differences between Process-based Vs Thread-based Multitasking

Frequently Asked Questions. 

What is preemption?

In computing, preemption is the act of preempting/stopping/pausing an ongoing process to execute a different process of higher priority.

What is a single-user operating system?

A single-user operating system is an operating system that allows only one user to access the computer at a time. The types of single-user operating systems are,

  • Single-user Single-tasking 
  • Single-user Multi-tasking

Examples of single-user operating systems are MS-DOS, Windows 95, Windows NT etc.

What is a multi-user operating system?

A multi-user operating system is an operating system that allows two or more users to access the computer at a time.

Examples of multi-user operating systems are mainframes like IBM AS400, Linux, and Unix Distributed OS.

Name some scheduling algorithms that are based on preemptive scheduling.

Scheduling algorithms in OS define how much CPU time can be allotted for a particular process. In the case of preemptive scheduling, the processor can be preempted at any time to execute a different process while it is already running a process. Some scheduling algorithms based on preemptive scheduling are

  • Round Robin (RR)
  • Priority (Preemptive version)
  • Shortest Remaining Time First (SRTF)

Conclusion

In this blog, we discussed multitasking in Operating systems. We also talked about the types of multitasking - process-based and thread-based multitasking.

If you are preparing for interviews, don’t forget to study Operating systems - as it is one of the most asked topics in interviews. You should check out our amazing course on Operating systems here, designed specifically for you! 

Recommended Readings:


Do check out The Interview guide for Product Based Companies as well as some of the Popular Interview Problems from Top companies like Amazon, Adobe, Google, Uber, Microsoft, etc. on Coding Ninjas Studio.

Also check out some of the Guided Paths on topics such as Data Structure and Algorithms, Competitive Programming, Operating Systems, Computer Networks, DBMS, System Design, etc. as well as some Contests, Test Series, Interview Bundles, and some Interview Experiences curated by top Industry Experts only on Coding Ninjas Studio.

Happy Learning Ninja!

Live masterclass