Table of Contents
A Computer system with a single CPU or a multi-processes system with fewer CPUs has to divide CPU time among the different processes or threads that are competing to use it. This process is called CPU scheduling. Preemptive and Non-preemptive are major types of CPU scheduling.
The operating system can make the computer more useful by switching the CPU among multiple processes. The goal of multiprogramming is to hold some processes running at all times. This should make the best use of CPU utilization.
Read Also:
If there is only one processor (or CPU) then there will only be one process in a running state at any given time. If there are more processes that require to be run, they will have to stay and wait. There must be some mechanism to select which process (currently in memory) will run next when the CPU becomes available.
The operating system maintains a ready queue. All the processes in this queue are in a standby position to be executed. Whenever a currently executing process needs to wait (does I/O etc.), the operating system picks a process from the ready queue and assigns the CPU to that process.
Scheduling is a fundamental operating system function. CPU is an important resource. So, it is very important to build up good scheduling algorithms.
Suppose we have two processes A and B to be executed. Each and every process executes for one second then holds for one second. It is repeated 60 times. If we run process A first and then process B, one after the other, it will take four minutes to run the two processes:
A takes two minutes to run and then B acquires two minutes to run. We in fact compute only two minutes of this time. The remaining two minutes are inoperative time. Our CPU utilization is only 50%.
Schedulers normally try to achieve some mixture of the following goals. These goals are conflicting to some level:
The process to choose the next job that will run on the CPU belongs to the short-term or CPU scheduler. The CPU scheduler can only select from the jobs that are already in memory and prepared to go. The scheduler works in cooperation with the interrupts system.
Major types of CPU scheduling are preemptive and Non-Preemptive. In Preemptive scheduling, a process may be removed from the CPU by force even it does not want to release the CPU when a higher priority process needs the CPU.
Whereas, in Non-Preemptive scheduling, a higher priority process waits for a currently running process to finish regardless of the priority e.g FCFS. Normally, there are four types of CPU scheduling:
There are four conditions under which the above types of CPU scheduling may take place. They are:
If only one condition 1 and 4 apply, the scheduling is called non-preemptive. All other types of CPU scheduling are preemptive. Preemptive means that a process may be forcibly removed from the CPU even if it does not want to release the CPU.
It is because a higher priority process needs the CPU. Once a process gets CPU, the simplest approach is to allow the process to continue using CPU until it voluntarily yields CPU by requesting an I/O transfer, etc. I/O interrupts may steal CPU from time to time.
After each interrupt, control passes back to the process that was running when it occurred. This is called a non-preemptive approach.
In a preemptive scheme, a running process may be forced to yield CPU by an external event instead of its own action. Such external events can be any or both of the following:
Timer interruption is a technique that is strongly interrelated to preemption. When a process acquires the CPU, a timer may be set to a specific period. If the process is still using the CPU at the end of the period, then it is preempted.
Both timer interruption and preemption force a process to yield the CPU before its CPU burst is complete. However, it is helpful to distinguish timer interruption from preemption caused by higher priority processes becoming ready for two reasons:
The dispatcher is a program that actually gives control of the CPU to a process selected by the CPU scheduler. It is another part of the scheduling system.
The functions of the dispatcher module are as follows:
The dispatcher should be very fast because it is called every time a process takes control of the CPU. The time that the dispatcher takes between stopping one process and starting another process is called dispatch latency.
There are a lot of scheduling algorithms and a variety of criteria to judge their performance. Different algorithms may support different types of processes. Some criteria are as follows:
A CPU scheduling algorithm should try to reduce the following:
A CPU scheduling algorithm should try to decrease the following:
CPU scheduling becomes much more complex when multiple CPUs are available. It is now possible for more than one job to run on a machine at any one time. The number of running jobs is equal to the number of processors.
An important issue is access to resources. Suppose only processor A has access to a certain device. others cannot access that device. any process that requires that devices have to be scheduled on processor A as other processors cannot satisfy its requests.
Another issue is that of contention. If two processes run on separate processors, they may try to update some shared data. It is also possible that two processors may try to grab the same process from the ready queue.
Some systems assign one master processor to do all the scheduling work. The master processor hands out the work to the slave processors who actually do the work. This ensures that there is only one processor responsible for scheduling work.
It should have all the information required to properly perform the scheduling. This approach requires no data sharing between processors.
There are two types of real-time systems:
The scheduler must ensure that a task is completed within a guaranteed amount of time.
The scheduler must ensure that the higher priority processes will run first. There is no guarantee that the process will finish within a specified time limit. The only guarantee is that the process will finish as soon as possible.
There are a number of scheduling algorithms and strategies. The choice of algorithm depends heavily on the most important criteria. Once an algorithm is selected, it should be evaluated. Here are some ways to evaluate an algorithm:
It takes a particular predetermined workload and defines the performance of the algorithm depending on that workload. This form of evaluation is simple and can be done quickly. However, it is not very general. We might get a completely different idea about the performance of an algorithm if we chose a different set of processes.
This approach does have some limitations. For example, the results may not be very exact as they rely on an approximation of the actual system.
A lot of processes are required to simulate an operating system. The processes should mimic those of typical users and the operating system itself that can be difficult. The simulation may take a long time to complete. For more accurate results, it may be necessary to use process information from a real system.
The only real way to test an operating system is to write the code and run it. However, this approach is very expensive.
Having bad credit can make it challenging to obtain a personal loan, but it's not… Read More
Traveling doesn't have to break the bank. With some careful planning and smart strategies, you… Read More
Are you looking for a job in the fruit packing industry with the added benefit… Read More
Are you considering a move from the United States to Canada? Whether it's for a… Read More
A credit card is a financial tool that allows you to borrow money from a… Read More
Watching sports online for free can be challenging due to the licensing agreements and restrictions… Read More