process management. contents process concept process states process description

74
PROCESS MANAGEMENT

Upload: colten-langland

Post on 02-Apr-2015

250 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

PROCESS MANAGEMENT

Page 2: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

ContentsContents

Process concept

Process states

Process description

Page 3: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Process

concept

Page 4: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Process definition

Informally, a process is a program in

execution

All the programs in execution are organized

as a set of sequential processes (process

model)

Page 5: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

A process is the unit of work in a

multiprogrammed system

a multiprogrammed O.S. allows concurrent

execution of more processes

Page 6: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

PO process : t1-tO, t3-t2, t5-t4

Multiprogramming

tO t1 t2 t3 t4

PO P1 PO P1 PO

t5

t

CPU activity

Page 7: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Program: algorithm description by a

programming language

Algorithm: the logical sequence of operations

that must be executed to solve

a problem

Page 8: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Process: the sequence of computer operations

during the execution of the program

Page 9: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Example: determine the MCD (maximum common

divisor)

of two integers greater than one (Euclid’s

algorithm)

Page 10: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

{

a = x; b = y;

while (a != b)

if (a > b) a = a – b;

else b = b-a;

}

Subtract the smaller number

from the larger one; repeat

until you get a zero or a one

Page 11: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

x 18 18 18 18 18 18

y 24 24 24 24 24 24

a - 18 18 18 12 6

b - - 24 6 6 6

initial state final

state

Page 12: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Process instances

More processes (instances) can be associated to

the same program; each

of them represents the execution of the same code

with different input data

Page 13: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

A process is identified by:

Program code

(text section)

Its current activity, represented by the

value of the PC and of the processor’s

registers

Page 14: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Process stack

(temporary data)

Data section

(global variables)

Page 15: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Several resources can be associated to one

process:

Open Files

Memory

I/O devices

Page 16: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Process

states

Page 17: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

active blocked

I/O or event wait

I/O or event completion

Page 18: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

The number of CPU is generally less than the

number of available processes

The active state is subdivided in two states:

Page 19: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

running

(a CPU is executing instructions of the

process)

ready

(the process is waiting to be assigned to a

CPU)

Page 20: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

blocked

allocation of

the CPU

preemption

of CPU

I/O or event wait

I/O o event completion

running

ready

Page 21: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

The ready state is logically equivalent to

running state: a process in ready

state could be executed

(if a CPU is available)

Page 22: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

A blocked process

cannot execute (even if the CPU is

available)

Page 23: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Additional states:

exit (a process that has completed or

aborted)

new (tipycally,a new process created to

execute a program, but not yet loaded in

the ready queue)

Page 24: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

blocked

allocation of

the CPUpreemption

of CPU

release

I/O or event completion

running

ready

exit

new

Page 25: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Additional state:

swapped (a process can

be swapped temporaly out

of memory to a backing store and then brought

back into memory for continued execution)

Page 26: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

init

ready running

sleeping

zombie

terminated

swapped

States of a UNIX process

Page 27: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Init: process

is loaded in memory.

The O.S. must build some tables to manage

it

Page 28: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Ready: the process is waiting to be

assigned to a processor

Running: instructions are being executed

Page 29: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Sleeping: the process is waiting for some

event to occur

Terminated: the process has finished

its execution

Page 30: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Swapped: the process

is temporarly trasferred

to a backing store

Page 31: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Zombie: the process

is terminated, but

it is waiting that the parent process collects

its status information

Page 32: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Multiprogrammed system (only one CPU):

One process

is being executed (running state)

Page 33: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

More others processes are waiting

to be executed by the CPU

(ready state)

for some event to occur (I/O completion o

reception of a signal) (waiting state)

Page 34: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Process

description

Page 35: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Process Descriptor

(Process Control Block-PCB):

Data structure associated

to each process

Page 36: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Process descriptor

Process state

Process context

CPU scheduling information

Mem. management information

Resource utilization

Accounting information

Page 37: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Process state

the state may be new, ready, running,

waiting, halted, and so on

Page 38: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Context

PC (the address of the next instruction to be

executed)

PS (cond.codes- flags int. en./dis. bit,

sup./user mode bit)

Page 39: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Cpu registers

The registers vary in number and type depending on

the computer architecture: accumulators, index

registers, stack pointers, general purpose registers

Page 40: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

CPU scheduling information

This information includes

a process priority, pointers to scheduling

queues, others scheduling parameters

Page 41: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Memory manag. information

the base and limit registers, the page tables or

the segment tables depending

on the memory system adopted

Page 42: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Accounting information

amount of CPU and real time used, time limits,

job or process numbers, and so on

Page 43: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Resource utilization

I/O devices allocated

to this process, a list

of open files and so on.

Page 44: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Scheduling queues

Ready queue: The processes that are residing in

main memory and are waiting to execute are kept

on a list called the ready queue

Page 45: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

This queue is generally implemented as a

linked list

Page 46: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Process queues

first last

O

first last

O

Page 47: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Blocked queue: The processes that are waiting for

some event to occur (I/O completion o

reception of

a signal) are kept on a list called the blocked

queue

Page 48: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

A new process is initially put in the ready

queue.

It waits there until it is selected for

execution

One of the following events can occur to

promote it:

Page 49: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

As a result of an I/O request the

process is placed in an I/O queue

Page 50: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

As a result of a creation of a subprocess

the process can wait

for its termination

Page 51: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

As a result of an interrupt, the

process

can be put back in

the ready queue

Page 52: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Context switch

The kernel saves the context of the old process in its

PCB.

The kernel inserts the PCB in the blocked or ready

queues (depending on the process state.)

Page 53: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

The kernel selects a new process from the ready queue

and its identifier is loaded in the execution process

register. (short term scheduling)

The context of the new process is loaded in the CPU

registers.

Page 54: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Context switch

Context-switch time is pure overhead, because the system

does no useful work while switching.

Its speed varies , depending on the mem. speed, the

number of regist. and special instructions.

Page 55: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Proces P execution

P PC

P PS

P SP

P R1

P Rn

PCB(P)

esecution process register

P context

Page 56: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

P PC

P PS

P SP

P R1

P Rn

PCB(P)

execution process register

P context

P context saving

Page 57: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

P1 context loading

PC

PS

SP

R1

Rn

PCB(P1)

execution process register

P1 context

P1

P1

P1

P1

P1

Page 58: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Scheduling

Page 59: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Process scheduling

A process is executed until it must wait, typically for

the completion of some I/O requests or because of

termination.

When the CPU becomes idle, the O.S must select one of

the processes in the ready queue to be executed.

Page 60: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Process scheduling

The selection process is carried out by the short term

scheduler, following particular policies.

Page 61: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Short term scheduler

CPU scheduling decision may take place:

1.When a process transits from the running state to the

waiting state(for example, I/O request).

2.When a process switches from the running state to the

ready state (for example , when an interrupt occurs).

Page 62: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Short term scheduler

3. When a process switchs from the waiting state to the

ready state ( for example, I/O completion) and its

priority is higher than the one of the executing

process

4. When a process complites

Page 63: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Short term scheduler

Non preemptive scheduling: once the CPU has been

allocated to a process,the process keeps the CPU until

it release the CPU either:

by teminating (4) or by switching to the waiting state

(1).

Page 64: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Short term scheduler

Preemptive scheduling: the currently running process

may be interrupted and moved to the ready state.

The decision to preempt may be performed when

conditions 2) or 3) occur.

Page 65: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Sistemi Operativi

Alternative scheduling policies

First-Come-First Served (FIFO)

When the currently running process ceases to execute,

the process that has been in the ready queue the

longest is selected for running. (nonpreemtive)

Page 66: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

RR (round robin)

Time sharing systems.

RR is preemptive: a small unit of time is defined

(time quantum) The ready queue is treated as a

circular queue.

RR goes around the ready queue, allocating the CPU to

each process for a time quantum.

Page 67: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Priority scheduling

A priority is associated with each process and the CPU is

allocated to the ready process with the highest priority.

Equal priority processes are scheduled in FCFS order

Priorities are generally some fixed range of

numbers(generally,low numbers represent high priority)

Page 68: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Multilevel queue scheduling

This scheduling algorithm partitions the ready queue into

several separate queues.

one process is permanently assigned to a queue, generally

based on some properties of the process such as memory

size,process priority, process type,…

Page 69: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Foreground (interactive) processes

Background (batch) processes

Foreground processes have priority (externally defined)

over the background processes.

Background processes run when the CPU is not

executing any foreground process

Page 70: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Starvation problem

A condition in wich a process is indefinitely delayed

because other processes are always given the preference.

For instance, a priority scheduling alghoritm can leave

some low-priority process waiting indefinitely

Page 71: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Medium term scheduling

Medium term scheduling is part of the swapping

function

The swapping decisions are based on the needs to

handle the correct degree of multiprogramming.

Page 72: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Long term scheduling

That determines wich programs are allowed to enter the

system for processing needs.

Once admitted the job becomes a process and it is added

to the ready queue managed by the short term scheduling

Page 73: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Long term scheduling

In a batch system,newly submitted jobs are routed to disk

and held in a batch queue

The decision as to wich jobs admit may include priority

or to keep a mix of CPU bound and I/O bound processes

Page 74: PROCESS MANAGEMENT. Contents   Process concept   Process states   Process description

Queueing diagram for scheduling

Ready queue CPU

I/O

completedI/O queue

wait for

interrupt

CPU preemption

I/O request

interrupt

init