Académique Documents
Professionnel Documents
Culture Documents
Tech CS&E
Problem definition:
One CPU with a number of processes. Only one process can use the CPU at a time and each process is specialized in one, and one task. Whats the best way to organize the processes (schedule them) ? [1] How will the CPU time be divided among the processes and threads competing to use it ? [2]
A pool of runnable processes are contending for one CPU; The processes are independent and compete for resources; The job of the scheduler is to distribute the scarce resource of the CPU to the different processes fairly and in an optimal way; The job of the dispatcher is to provide the mechanism for running the processes; The OS is a multitasking, but not a multiprocessor, one;
Waiting time
Response time
Keep it as high as possible Number of processes completed per unit time Amount of time spent ready to run but not runnin Amount of time between submission of requests and first response to the request Minimize the overhead Mean time from submission to
Resources:
Preemptible:
Take resource away, use it for something else, then give it back. (e.g. processor or I/O channel)
Processes:
IO bound:
Perform lots of IO operations.
CPU bound:
Perform lots of computation and do little IO
Non-preemptible:
Once give, it cant be reused until process gives it back. (e.g. file space or terminal)
The states of a process, at any given time, is comprised of the following minimal set:
Running: The CPU is currently executing the code belonging to the process. Ready: The process could be running, but another process has the CPU. Waiting: Before the process can run, some external event must occur.
Round Robin
Process runs for one time slice, then moved to back of the queue; Each process gets equal share of the CPU.
Priority Systems
The highest priority ready process is selected In case of a tie, FCFS can be used Priorities could be assigned:
Externally (e.g. by a system manager) Internally (e.g. by some algorithm) Combination of external and internal
Preemptive schemes:
Once a process starts executing, allow it to continue until it voluntarily yields the CPU
Non-preemptive schemes:
A running process may be forced to yield the CPU by an external event rather than by its own action
Allows multiple users slices of the CPU on a round robin basis Majority of users have the same priority Not a popular scheme with dynamic priority systems
For each process, identify duration (i.e., length) of its next CPU burst. Use these lengths to schedule process with shortest burst Two schemes:
Non-preemptive once CPU given to the process, it is not preempted until it completes its CPU burst Preemptive if a new process arrives with CPU burst length less than remaining time of current executing process, preempt.
This scheme is known as the Shortest-Remaining-Time-First (SRTF)
of long one. SJF is provably optimal gives minimum average waiting time for a given set of process bursts
Moving a short burst ahead of a long one reduces wait time of short process more than it lengthens wait time
Scheduling
13
P1
P2
P3
P2
P4
P1
Scheduling
14
A priority number (integer) is associated with each process CPU is allocated to the process with the highest priority (smallest integer highest priority)
Preemptive nonpreemptive
Scheduling
15
Highest priority runs next May be done with multiple queues multilevel
Scheduling
16
Problem: Starvation low priority processes may never execute Solution: Aging as time progresses, increase priority of waiting processes
Scheduling
17
General theme what is the best way to run n processes on k resources? ( k < n) Conflicting Objectives no one best way
Incomplete knowledge
Real world limitations
E.g. does user know how long a job will take E.g. context switching takes CPU time Job loads are unpredictable
Scheduling
18