Você está na página 1de 5

CPU Scheduling

Introduction: The assignment of physical processors to processes allows process to accomplish work. This assignment is handled by the Operating System. This is called CPU scheduling. The following are the two types of scheduling. They are (i). Non-Preemptive Scheduling (ii). Preemptive Scheduling

(i). Non-Preemptive Scheduling: In a scheduling, once the CPU has been allocated to a process keeps the CPU until it releases the CPU either by terminating or by switching to the waiting state. This scheme of scheduling is called as Non-Preemptive scheduling. (ii). Preemptive Scheduling: In a scheduling scheme, a process in execution is forced to release the CPU, so that some other process can be executed. This scheme of scheduling is called as Preemptive scheduling.

The CPU scheduling discussion may take place under the following situations: 1. When a process switches from the running state to waiting state. 2. When a process switches from the running state to ready state. 3. When a process switches from the waiting state to ready state. 4. When a process terminates. In the above statements 1 & 4 is Non-Preemptive Scheduling. 2 & 3 are Preemptive Scheduling.

CPU Scheduling Criteria


The CPU scheduling algorithm may have different properties. To choose a best algorithm for a process, some of the following criteria suggested. * CPU utilization * Throughput * Turnaround time * Waiting time * Response time

CPU utilization: We want to keep the CPU as busy as possible. Throughput: The number of process that is completed per time unit is called throughput. Turnaround time: The interval from the time of submission to the time of completion of a process is called as turnaround time. Waiting time: It is the sum of the periods spent waiting in the ready queue. Response time: It is the measure of the time from the submission of a request until the first response is produced. It is always desirable to maximize CPU utilization and throughput. Minimize turnaround time, waiting time, response time.

CPU Scheduling Algorithm


CPU scheduling deals with the problem of the process in the ready queue to be allocated the CPU. There are many CPU scheduling algorithms. i. ii. iii. iv. v. vi. vii. First come - First served scheduling Shortest job first scheduling Priority scheduling Round Robin scheduling Multilevel queue scheduling Multilevel feedback scheduling Multiple processor scheduling

(i). First come First served scheduling: The process that requests the CPU is first allocated to the CPU first. This is easily implemented by the FIFO queue data structure. When the process enters the read queue, it is linked on to the tail of the FIFO queue. When the CPU is free it is allocated to the process at the head of the cube. The average waiting time under the FCFS scheduling is long. Consider the following set of process that arrives at the time zero with length and CPU burst time given in milliseconds.

Process P1 P2 P3

Burst Time 18 ms 12 ms 15 ms

If the process align in the order of P1, P2, P3 we schedule the process according to the following chart. P1 0 18 P2 30 P3 45

(ii). Shortest job first scheduling: When the CPU is available, it is assigned to the process that has the smallest next CPU execution. If two processes have the same length of next CPU burst (execution), shortest job will be scheduled first. We schedule the process according to the following chart.

Process P1 P2 P3 P4 P4 0 4 P1 12

Burst time 8 ms 10 ms 9 ms 4 ms P3 21 P2 31

The waiting time in milliseconds for process P1 is 4. P3s waiting time is 12. P2s waiting time is 21. erage 4 12 21 31 4 =9

(iii). Priority Scheduling: In this scheduling, a priority is associated with each process. The CPU is allocated to the process with the highest priority. Let us consider the following set of process in the order of P1, P2, P3, P4, and P5 with CPU execution (burst) time and priority. Process P1 P2 P3 P4 P4 Burst time 12 ms 1 ms 3 ms 5 ms 2 ms Priority 3 1 2 4 2

P2 0 1

P5 3

P3 6

P1 18

P4 23

erage =5.6

1 2 6 1 5

Você também pode gostar