DEV Community

Syed Muhammad Ali Raza
Syed Muhammad Ali Raza

Posted on

Scheduling in Operating Systems

Scheduling is an important aspect of the operating system that is responsible for managing and optimizing the execution of computer operations. The system ensures efficient resource utilization and timely completion of tasks. In this article, we will explore the basics of scheduling, its types, and provide examples to illustrate different scheduling algorithms.

Introduction:

In a multithreaded environment, several processes compete for the CPU (Central Processing Unit) to execute instructions. Scheduling involves determining the order of execution of operations and allocating resources for each process. Effective scheduling contributes to system responsiveness, resource utilization, and overall performance.

Scheduling Types:

1. Long Term Scheduling (Job Scheduling ):

Long-term planning involves selecting a process from the job pool and loading it into a ready queue. Determines which operations are accepted into the system to run. The goal is to maintain a balance between system throughput and fairness.

2. Short Term Plan (CPU Scheduling ):**

The short-term plan determines which process will be executed next. These decisions are made frequently, often several times per second. Common CPU scheduling algorithms include:

  • First Come, First Served (FCFS): Operations are executed in the order they arrive.

  • Shortest Job Next (SJN): The shortest burst time is executed first.

  • Priority Scheduling: Each process is prioritized and the highest priority process is executed first.

  • Round Robin (RR): Each process is given a specific time and they are executed in round robin fashion.

3. Medium Term Scheduling :

The medium term plan includes swapping in and out of memory. When a process is forgotten, it is considered suspended. This helps improve overall system performance and allows for better resource utilization.

Examples of scheduling algorithms:

1. First Come First Service (FCFS):

Consider the scenario with the process P1, P2, P3 arriving in the order of P1, P2, P3. The FCFS schedule will be executed in the same order, regardless of the burst time.

| S1| S2| S3|
------------------
0 5 9 14
Enter fullscreen mode Exit fullscreen mode

2. Next Shortest Job (SJN):

We calculate the burst times for P1, P2, and P3 as 6, 2, and 8 units, respectively. SJN will do P2, P1, P3.

| S2| S1| S3|
------------------
0 2 8 16
Enter fullscreen mode Exit fullscreen mode

3. Round Robin (RR):

Consider the process P1, P2, P3 with a duration of 4 units. Execution will continue in a round-robin manner until all executions are completed.

| S1| S2| S3| S1| S2| S3| S1|
-------------------------------------
0 4 8 12 16 20 24 27
Enter fullscreen mode Exit fullscreen mode

Result:

Scheduling is an important part of the operating system that affects system performance, responsiveness, and resource utilization. Different scheduling algorithms serve different purposes and their effectiveness depends on the nature of the problem and system requirements. Understanding these algorithms is essential to designing efficient operating systems that meet the demands of modern computing.

Top comments (0)