Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

operating system

What is pre-emptive multitasking?

Ayesha Naeem

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Pre-empting in operating systems means taking the control of the operating system from one process and handing it over to another process.

Pre-emptive multitasking means sharing the operating system and resources between multiple tasks.

Explanation

A time-sharing condition enables pre-emptive multitasking. Each task is allocated a slice of time from the computing resources. The tasks may share the time, or the operating system may allocate an additional amount of time slices depending on the importance and priority of the tasks.

The operating system initiates an interrupt mechanism to withdraw resources from a process, and then allocates them to another process.

Figure 1 provides an example of how pre-emptive multitasking takes place when tasks are scheduled by priority. Initially, Task 1 with a low priority is executing. Task 2 with a higher priority arrives, and its execution begins while the execution of Task 1 stops. Task 3 with an even higher priority arrives and runs to completion, while the execution of Task 2 is halted and resumes only after Task 3 is completed. Execution of Task 1 resumes after Task 2 completes.

RELATED TAGS

operating system

CONTRIBUTOR

Ayesha Naeem
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring