Operating system (3)--process scheduling algorithm.

1. Scheduling algorithm indicators:

2. Scheduling algorithm (1):

        1. First come, first served (FCFS):

        2. Short Job First (SJF):

        Non-preemptive:

         Preemptive:

        3. High response ratio priority (HRRN):

        3. Scheduling algorithm (2): 

        1. Time slice scheduling algorithm:

2. Priority scheduling algorithm:        

        Non-preemptive:

        Preemptive:

         3. Multi-level feedback queue algorithm:

        4. Multi-level queue scheduling algorithm:


 1. Scheduling algorithm indicators:

2. Scheduling algorithm (1):

Suitable for early batch operating systems, not for modern interactive operating systems.

1. First come, first served (FCFS):

  • The advantage is that it is extremely fair, as long as you come first, I will serve you first.
  • The disadvantage is that it is extremely unfriendly to short jobs and may wait for a long time.
  • Starvation does not occur.

2. Short Job First (SJF):

  • Whoever has short time, the operating system will serve first.
  • Process short job processes as quickly as possible. Both average wait time and average turnaround time are shorter.
  • Only the shortest time is considered each time, and the waiting time is not considered, so it will cause starvation, because there are continuous short jobs and long jobs will continue to wait.

Non-preemptive:

Each time the process that has currently arrived and has the shortest time is selected.

 Preemptive:

First select the one with the shortest time that has currently arrived, and then when a new task arrives in the ready queue, it will calculate the remaining time of the process in the current ready queue, and schedule the CPU with the shortest remaining time to run.

3. High response ratio priority (HRRN):

When a process voluntarily gives up the right to use the CPU, the response ratio of the process in the ready queue is calculated, and the one with the highest corresponding ratio is selected for scheduling.

3. Scheduling algorithm (2): 

It is more suitable for interactive systems.

  

1. Time slice scheduling algorithm:

Allocate time for each process according to the time slice. When the time slice time is up, the process will be called out automatically, then put it at the end of the queue, and schedule the process at the head of the queue to run on the CPU.

  • If the time slice is too large , the time slice scheduling algorithm degenerates into a first-come, first-served algorithm, and increases the corresponding time of the process.
  • If the time slice is too small, the process switching will be too frequent and the system overhead will be increased.

2. Priority scheduling algorithm:

Attach a priority number to each process, and select which process to schedule according to the priority number. for real-time operating systems.

  •  If a process with a higher priority continues to come over, it will cause a long wait with a low priority, resulting in starvation. 
  • The opportunity for each process to be served can be flexible.

Non-preemptive:

The ones that arrive now are served first. If they arrive at the same time, the ones with higher priority will be given priority to run.

Preemptive:

Priority is given to running the process with the highest priority that has currently arrived. When the current process gives up the processor or the ready queue changes, it will check again whether it needs to schedule a process with a higher priority.

 3. Multi-level feedback queue algorithm:

1. Create a multi-level queue. The priority of these queues decreases sequentially from top to bottom, but the time slice size increases sequentially. Each arriving process will be prioritized in the highest queue (first come, first served).

2. When the time slice of the current process in the highest queue expires, it will be placed at the end of the next-level queue to wait for scheduling.

3. Only when there is no ready process or running process in the upper-level queue will the scheduling of the next-level queue process be considered.

4. In the last level of queue, if the time slice has not finished running, it will still be placed at the end of the lowest queue and continue to wait for scheduling.

Can lead to starvation, because the continuous short process input will cause the low priority process to continue to wait.

1. Set up multi-level ready queues. The priorities of queues at all levels are from high to low, and the time slices are small to large.

2. When a new process arrives, it enters the first-level queue first, and queues up according to the FCFS (first come, first served) principle to wait for the allocated time slice. If the time slice is used up and the process has not ended, the process enters the tail of the next-level queue. If it is already in the lowest-level queue at this time, it will be put back at the end of the lowest-level queue

3. Only when the k-level queue is empty, will the time slice be allocated to the k+1 queue head process.

4. The process of the preempted processor will be put back into the tail of the original queue.

5. If it is at the last level and the process is still not running after the time slice arrives, continue to put the process at the end of the lowest level queue.

4. Multi-level queue scheduling algorithm:

Create multiple queues in the system, these queues have priorities, and the internal scheduling algorithms of each queue are also different.

Guess you like

Origin blog.csdn.net/weixin_60414376/article/details/126969101