Vous êtes sur la page 1sur 45

Process

Several definitions of process : A program in execution An asynchronous activity The entity to which processors are assigned The dispatchable unit

Process states
A process goes through a series of discrete process

states such as below (basic states):


Running state if it currently has the CPU Ready state if it could use a CPU if available Blocked state if it is waiting for some event to happen

(eg an I/O completion event)before it can proceed

Process states
During process state transition, 2 types of list are

established, which are :


Ready list Blocked list

Process states
Ready list Consists of ready processes Is maintained in priority order The next process to receive the CPU is the first process in the list

Process states
Blocked list Consists of blocked process Normally unordered Processes will become unblocked in the order in which the events they are waiting for occur

Process State Transition


Dispatching process is a process of assigning CPU to

the first process on the ready list (Refer next diagram)

Process State Transition


Running Dispatch Timerrunout Block

Ready

Blocked

Wakeup

Process control blocks(PCB)


A data package containing all information needed to

keep track of a process when switching

Process control block(PCB)


It contains: An ID number that identifies the process Pointers to the locations in the program and its data where processing last occurred Register contents States of various flags and switches Pointers to the upper and lower bounds of the memory required for the process A list of files opened by the process The priority of the process The status of all I/O devices needed by the process

Interrupt
An event that change the sequence in which a

processor execute instructions Prevents a process from monopolizing the system OS sets interrupting clock/interval timer to allow user to run in a specific time interval.
If process does not free CPU in interval time,

interrupting clock generates an interrupt that cause OS to regain control OS turn the previously running process to ready, and makes the first process on the ready list running

Types of scheduling processes:


Long-term scheduling
Medium-term scheduling Short-term scheduling

Long-term scheduling
determines : which and when certain programs are admitted to the system for execution which and when certain programs should be exited runs relatively infrequently, when a decision must be

made as to the admission of new processes: on average every ten seconds.

Long-term scheduling
once a new process is accepted (and partially created)

it may enter the scheduling queues in one of two places:


If all resources (such as memory requirements) are

initially fully available to the new process, it may be admitted to the tail of the Ready queue. If not all resources are immediately available, the new process may be instantiated in the Blocked-Suspended queue until those resources are provided.

Medium-term scheduling
determines when processes are to be suspended and

resumed The medium-term scheduler runs more frequently, deciding which processs pages to swap to and from the swapping device: typically once a second.

Medium-term scheduling
the success of the medium-term scheduler is based on

the degree of multiprogramming that it can maintain, by keeping as many processes runnable as possible. more processes can remain executable if we reduce the resident set size of all processes. makes decisions as to :
which pages of which processes need stay resident, and

which pages must be swapped out to make room for

other processes.

Short-term scheduling
determines which of the ready processes can have CPU

resources, and for how long. also called as the dispatcher executes most frequently(every few hundredths of a second) making fine-grained decisions as to which process to move to Running next.

Short-term scheduling
is invoked whenever an event occurs
provides the opportunity, or requires, the interruption

of the current process and the new (or continued) execution of another process.

Scheduling algorithms:
First in first out(FIFO)
Round robin scheduling (RR) Shortest job first (SJF) Shortest remaining time (SRT) Priority (P) Multilevel queue (MLQ) Multilevel feedback queue (MLFQ)

First In First Out(FIFO)


The simplest scheduling discipline
Processes are dispatched according to their arrival

time on the ready queue Process that has the CPU will run until complete Non preemptive scheduling algo.

First In First Out(FIFO)


Disadvantage: Long jobs make short jobs wait Unimportant jobs make important jobs wait Not useful in scheduling interactive users because it does not guarantee good response times

First In First Out(FIFO)


Rarely used as a master scheduling algo but often

embedded within other algo.


Eg many scheduling algo dispatch processes according

to priority but processes with the same priority are dispatched FIFO

FIFO
Ready list

CPU
Dispatch

Completion

Running

Block

Timerrunout

Ready

Blocked

Wakeup

Round Robin(RR)
Process are dispatched FIFO but are given a limited

amount of CPU time(time-slice or quantum) If a process does not complete before its CPU time expires, the CPU is preempted and given to the next waiting process The preempted process is placed at the back of the ready list

Round Robin(RR)
Advantage: Effective in timesharing environments in which the system needs to guarantee reasonable response times for interactive users

Round Robin(RR)
Ready list Completion

CPU

(complete within CPU time)

Preemption
(does not complete before CPU time expires)

Shortest Job First(SJF)


Non preemptive scheduling algorithm
Process with the smallest estimated run-time-to-

completion is run next Advantage :


Minimize the average waiting time of jobs

Disadvantage : Not useful in timesharing environment

Shortest Remaining Time(SRT)


Preemptive version of SJF
Process with the smallest estimated run-time to

completion is selected to run next, including new arrivals A running process may be preempted by a new process with a shorter estimated run-time

Shortest Remaining Time(SRT)


Advantages : short processes are handled very quickly useful in timesharing environment requires very little overhead since it only makes a decision when a process completes or a new process is added, and when a new process is added the algorithm only needs to compare the currently executing process with the new process

Shortest Remaining Time(SRT)


Disadvantages : it has the potential for process starvation for processes which require a long time to complete if short processes are continually added

Priority
A priority is associated with each process
The CPU is allocated to the process with the highest

priority Priority can be defined either :


internally externally

Priority
Internally defined priorities use some measurable

quantities to compute the priority of a process. E.g.


time limits, memory requirements, no. of open files,

ratio of average I/O burst time to average CPU burst time etc.

Priority
External priorities are set by criteria that are external

to the OS, such as :


the importance of the process, the type and amount of

funds being paid for computer use, the department sponsoring work and other often political factors.

Priority
Priority scheduling can be : preemptive or non preemptive.

Priority
A preemptive priority scheduling algorithm will

preempt the CPU if the priority of the newly arrived process is higher than the priority of the currently running process.

Priority
A non preemptive priority scheduling algorithm will

simply put the newly arrived process at the head of the ready queue.

Priority
Disadvantage : indefinite blocking or process starvation. This can be solved by a technique called aging wherein we gradually increase the priority of a long waiting process.

Multilevel Queue
Partitions the ready queue into several separate

queues. The processes are permanently assigned to one queue based on some property of the process. Eg :
Interactive process
Batch process

Multilevel Queue
Each queue has its own scheduling algorithm.
In addition, there must be scheduling between the

queues which is mostly implemented as fixed priority preemptive scheduling

Multilevel Queue
Ready Queue 1
System Processes SJF

Processor Ready Queue 2


Inter queue scheduling (mostly implemented as fixed priority preemptive scheduling)

Interactive Processes RR

Ready Queue 3
Batch Processes FIFO

Multilevel Feedback Queue (MLFQ)


Has a number of queues, each assigned a different

priority level. A job that is ready to run can only be on a single queue.

Multilevel Feedback Queue (MLFQ)


Uses priorities to decide which job should run at a

given time:
a job with higher priority (i.e., a job on a higherqueue) is

the one that will run.

If there is more than 1 job with the same priority at a

given queue at the same time.


roundrobin scheduling is used among those jobs

Multilevel Feedback Queue (MLFQ)


MLFQ varies the priority of a job based on its observed

behavior. Eg:
If, for example, a job repeatedly release the CPU while

waiting for input from the keyboard, MLFQ will keep its priority high. If a job uses the CPU intensively, MLFQ will reduce its priority.

In this way, MLFQ will try to learn about processes as

they run, and thus use the history of the job to predict its future behavior.

Multilevel Feedback Queue (MLFQ)


Rules of MLFQ: Rule 1: If Priority(A) > Priority(B), A will run and B wont Rule 2: If Priority(A) = Priority(B), both A and B will be run in round-robin fashion Rule 3: When a job enters the system, it is placed at the highest priority (the topmost queue). Rule 4: Once a job uses up its quantum at a given level (regardless of how many times it has given up the CPU), its priority is reduced (it moves down one queue). Rule 5: After some time period S, move all the jobs in the system to the topmost queue

Multilevel Feedback Queue


Queue 1, quantum = 10 milisec.

Priority 1

Queue 2, quantum = 40 milisec.

Priority 2

Queue 3, FIFO

Priority 3

Vous aimerez peut-être aussi