Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
MCQs
3.
Frequently asked questions
4.
Conclusions
Last Updated: Mar 27, 2024
Easy

CPU Scheduling || Part-2

Author Ankit Kumar
1 upvote
Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

Introduction

In this article, we will discuss some of the important questions related to CPU scheduling algorithms. We will see some of the theoretical and numerical questions related to scheduling as well and will hope that you can extract benefits from this and do well in your upcoming interviews. The Multiple-choice questions will be followed by their answer and a brief explanation about them.

Let us begin with the MCQs.

MCQs

1.Let us consider three processes with process id 1, 2, and 3, respectively, and their burst time is 1, 3 and 7-time units, respectively. Every process arrives at time zero. Let us suppose the CPU follows the longest remaining time first (LRTF) scheduling algorithm, and In LRTF, ties will be broken by giving priority to the process with the lowest process id. What will be the average turnaround time for these three processes?
     A. 13 units
     B. 15 units
     C. 10 units
     D. 12 units
Ans Option C
Explanation - If the CPU follows an LRTF algorithm, then the processes will be executed in the following order.

With the above Gantt chart, we can derive the following things.
Turn around time for P1 is (9-0) = 9
Turn around time for P2 is (10-0) = 10
Turn around time for P3 is (11-0) = 11
Hence the average turn around time is (9+10+11)/3 = 30/3 = 10 units.

2. Let us Consider the three processes, P0, P1 and P2, given in the following table.

What will be the order of completion of the CPU following the First Come, First Serve scheduling algorithm?
     A. P0 - P1 - P2
     B. P1 - P2 - P0
     C. P2 - P1 - P0
     D. P0 - P2 - P1
Ans - Option D
Explanation -  The first-come, the first-serve scheduling algorithm is a non-preemptive kind of algorithm that executes the process which arrived earliest in the CPU unless they need to perform I/O operations. In the given scenario, there are no I/O operations required by any one of the processes, so the order of execution of the processes will be P0 - P2 - P1.
Hence option d will be the correct answer.

3. Match the following groups, where column1 contains some of the CPU scheduling algorithms, and column2 contains their applications.


Choose the correct option
     A. 1-A, 2-B, 3-C
     B. 1-B, 2-C, 3-A
     C. 1-C, 2-B, 3-A
     D. 1-B, 2-A, 3-C

Ans Option C
Explanation - Gang scheduling is a kind of scheduling algorithm that schedules related threads to run simultaneously on different processors. The Fair-share scheduling algorithm distributes the CPU usage equally to all the processes; hence it is a guaranteed scheduling algorithm, and the Rate monotonic scheduling algorithm is used in real-time operating systems due to its scheduling strategy. Hence Option C is the correct match for this problem.

4. What is the maximum number of processes that can be in a Ready state for a computer system with n CPUs?

     A. n
     B. n^2
     C. 2n
     D. Not dependent on n

Ans Option D

Explanation - The maximum number of processes that can be in the ready state is not at all dependent on n, as there can be an infinite number of processes present in the ready state.

5. Which of the following statement is/are incorrect about SJF (Shortest Job first scheduling algorithm)?
Statement 1 - The average waiting time is minimum for it.
Statement 2 - It causes starvation.
     A. Only statement 1
     B. Only statement 2
     C. Both of the Statements
     D. None of the statements
Ans Option D
Explanation - The Shortest Job First algorithm can cause starvation for the process with a significant amount of burst time as there is no concept of priority in it, and the average waiting time is though optimal but not minimum in the SJF algorithm.
With this, we end this blog. Let us now see some of the Frequently Asked Questions.

Also See, scheduling algorithms in operating system

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Frequently asked questions

  1. What are CPU scheduling algorithms?
    The CPU needs some set of predefined rules to schedule the processes effectively.
    These predefined rules are the CPU scheduling algorithms.
  2. Name some of the CPU scheduling algorithms?
    The following list contains some of the CPU scheduling algorithms.
    1. First come, first serve
    2. Round-robin/Time-sharing
    3. Shortest Job First
    4. Priority scheduling
  3. How many types of CPU scheduling algorithms are there?
    There are two types of CPU scheduling algorithms
    1. Preemptive scheduling
    2. non-preemptive scheduling
  4. Explain Preemptive and Non-preemptive scheduling.
    The preemptive scheduling algorithms can interrupt the process getting executed and start executing a new process anytime. Still, in non-preemptive scheduling algorithms, the process can not be interrupted unless the process requires some input-Output operations to execute. 
  5. What is a Deadlock?
    Deadlock is an unwanted situation in which the resources required by a process are acquired by another process and vice versa. Thus, both the processes are unable to execute as they wait for each other.

Let us now summarize our learnings.

Conclusions

In this article, we have extensively discussed some of the important questions related to CPU scheduling. We also answered those questions along with a brief explanation about them.

In the end, we also discussed some of the frequently asked questions.

If you want to learn more questions on CPU scheduling, then read CPU scheduling part 1.

We hope that this blog has helped you enhance your knowledge regarding CPU scheduling in the Operating system. If you would like to learn more, check out our articles on Coding Ninjas Studio. Do upvote our blog to help other ninjas grow. Happy Coding! 

Previous article
CPU Scheduling Part 1
Next article
What is Loader?
Live masterclass