Top Banner
PROCESS MANAGEMENT Y. Colette LeMard
56

PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Mar 29, 2015

Download

Documents

Rodolfo Hunsley
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

PROCESS MANAGEMENT

Y. Colette LeMard

Page 2: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

PROCESS MANAGEMENT

The management of running programs is one of the functions of the Operating System

Page 3: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

The basic unit of software that the operating system deals with is … a process.

A process is defined as a running program(It exists in memory, is performing some action and can be controlled by a user, an application or the operating system).

A program is only regarded as a process when it is being executed.

Page 4: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Processes

Examples of processes are :

– A game being played– MS Word running– Data being transmitted along a network– Antivirus software running

Processes may be system processes or application processes

Page 5: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Processes

In order for processes to run properly to completion they need computer resources such as :

– CPU time– Memory– Files (on secondary storage devices) and– I/O devices in order to complete their

tasks.

Page 6: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Processes

Resources are normally allocated to the process when it is created

Processes may also require initialization data and these are also supplied on creation.

Page 7: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Processes

Processes are created when the program first begins to run.

It may be started by the O/S itself, by a utility or by a user/application program

Page 8: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Processes

As a process runs there are several

possible states that it may be in

depending on what is happening in the

process itself, and also in the overall

system

Page 9: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Processes

The states are :

READY – the process can use the CPU if the CPU is available

RUNNING – The process is being executed by the CPU

BLOCKED – The process is waiting for an event to happen before it can continue. Otherwise called “waiting”

ENDED - The process is no longer running

Page 10: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

Process States

Ready Waiting

EndedRunningCreated

Page 11: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

Any number of processes can be READY at the same time so a READY QUEUE is maintained for all processes hoping to run soon.

Only one process at a time can have the status RUNNING

A queue of BLOCKED or WAITING processes is also maintained.

Page 12: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

Managing the queues and the execution of programs is one of the major roles of the O/S.

Page 13: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

The operating system performs many tasks on processes as they execute

Page 14: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

The O/S can 1.

- Create a process : the program is

brought into memory (RAM) and given a

process control block.

Its status is then set to READY

Page 15: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

The PCB is a small piece of memory that stores information about a running program. Every process has a PCB

Typically the PCB stores the following data : the process id, the user name, the time

started, the priority, the state, the time elapsed, data registers, etc..

Page 16: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

The PCB is sometimes called the

process descriptor in your syllabus

Page 17: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

The O/S can 2.

- Destroy / Kill a process : this involves terminating a process before it has run to completion.

This may be initiated by the user, the application or the system and then

performed by the O/S.

Page 18: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

The O/S can 3.

- Suspend a process : the process is

paused as the CPU’s attention is given

to another process. Its status is

changed to either WAITING or READY

and it goes to the appropriate queue

Page 19: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

The O/S can 4.

- Resume a process : a suspended

process once again regains the

attention of the CPU. It’s status

therefore becomes running

Page 20: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

The O/S can : 5.

Change a process’ priority : The priority is a

rating that determines the process’ position in

the ready queue. The priority can be upgraded

or downgraded, making the process more

important or less important, and thus changing

how long a waiting time it has.

Page 21: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

A single CPU can only attend to one process at a time.

Yet many O/Ss give the appearance that they can simultaneously run many programs.

Page 22: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

When the Operating System executes more than one process concurrently so that they appear to be running at the same time, it is said to be multiprogramming. They are active in memory at the same time but only one is being executed by the CPU

Page 23: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

The CPU is so fast that it appears that it is doing several things at the same time when in fact it is doing them one after the other in small time slices.

Page 24: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

Multiprogramming

An operating system managing several

processes at the same time so it

appears as if they all being executed by

the CPU at the same time.

Page 25: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

One way of accomplishing this :

The operating system assigns a time slice to every process that it creates in units of CPU cycles.

Once it is not interrupted, the process has the attention of the CPU for that number of cycles.

The other processes wait in the ready queue

Process Management

Page 26: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

When the time is up the process state is set to ready and stored in the PCB along with the current data. The CPU then moves the process to the back of the ready queue.

The CPU next takes the process at the front of the ready queue and begins to work on it. It runs for that time slice and the technique is repeated.

Page 27: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

Eventually the earlier process gets another time slice. This is called the round-robin approach

The combination of the small time slice and the speed of the CPU means that it appears that all the processes are running at the same time. This complex operation is managed by the operating system.

Page 28: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

The O/S uses one of the following techniques called Scheduling Algorithms to decide which program will run next.

1. Shortest job first (SJF)2. Shortest remaining time first (SRTF)

These are called pre-emptive algorithms

Page 29: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

Scheduling Algorithms cont’d

4. First come first serve (FCFS)5. Priority scheduling6. Round robin

These are called non-pre-emptive algorithms

Page 30: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

. Note : the O/S aims to do the following :

– Process the maximum number of jobs– Be as fair to each user as possible– Provide acceptable response times to online users– Keep the devices busy– Avoid deadlock– Degrade gracefully, instead of freezing, if the system

is overloaded.

Page 31: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

Often an operating system uses a combination of strategies.

Example Shortest job first may be combined with priority scheduling. After all, if two or more jobs have the same priority some other mechanism must be used to decide which gets executed first.

Page 32: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

Questions ?

Page 33: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

There are times when a process needs the attention of the CPU even though it may not be its time to run yet.

Page 34: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

External operations such as getting data from the disk or printing (I/O operations) are much, much slower than the CPU.

So instead of waiting for these operations to complete, the O/S will block that process (set it to waiting) and send another one which is ready to the CPU

Page 35: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

E.g.

– when a process needs data or is printing. When the print starts the CPU sends the request to the device driver and the O/S moves the process into the waiting queue.

Page 36: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

When the I/O operation is complete the waiting process generates an

INTERRUPT to the O/S.

An interrupt is a special signal sent by the hardware or the software to gain

the CPU’s attention.

Page 37: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

There are four types of interrupts :

– Interrupt generated by a running process

– Input/output interrupt– External interrupt– Restart interrupt

Page 38: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

e.g. A hardware interrupt is sent by printers to the CPU to tell it when they have finished printing a job

Page 39: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

The CPU will then respond by completing the step it is on, pausing what it was doing and storing the data for the current process in its PCB,

Page 40: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

It will then check to see the type of interrupt, go to the interrupt routines to determine how to handle this particular interrupt, and then execute the interrupt routine.

When it is finished handling the interrupt it puts the job in the ready queue and then return to the original process.

Page 41: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

While this sounds like a long process, it is usually done in a few millionths of a second so that the user does not even know that it has happened.

Sometimes there can be scores of interrupts per second.

Page 42: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

Interrupts can be generated by :– Hardware device not working properly– A mouse click– A Keyboard character pressed– Drive fault– System error– Printing finished

Page 43: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

QUESTIONS ?

Page 44: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

LOCKS When a process is using a resource it locks

it, so that there can be no conflict in use. This prevents lots of possible errors e.g.

two users trying to change the same data at the same time.

Page 45: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

Howeverwhen several processes are attempting to use a number of

resources, it is possible for

a situation known as

DEADLOCK

to occur.

Page 46: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Example …

Lets say Process1 opened a file called FileA.

It then attempts to use the printer.

Process2 is however using the printer so ProcessI has to wait.

Page 47: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

While still using the printer Process2 finds a need to use FileA. When it attempts to do so it finds that FileA is already in use by Process1.

So Process2 goes to the waiting queue to wait on Process1 to free up the file.

Page 48: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

This will never happen because

Process1 is also in the wait queue waiting on Process2. So both are in the waiting queue waiting

on each other -

Thus we have DEADLOCK

Page 49: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Process Management

To avoid deadlocks we can take the following steps:

Do not allow a process to start until all its resources are available

Always allocate resources in the same sequence e.g. data then printer

If deadlock does occur the O/S is allowed to end a process.

Page 50: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Classifications of

Operating Systems

Single user – an o/s designed to be used by one person at a time

Multi-user - allows several users access concurrently; eg midrange systems such as mainframes where one computer has many users running different programs from multiple attached terminals

Page 51: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Classifications of

Operating Systems

Single tasking – an o/s that can only execute one process at a time

Multiprogramming – capable of executing several processes at once by use of a scheduling algorithm for the CPU

Page 52: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

Classifications of

Operating Systems

Multiprocessing – having more than one processor available for running processes

Network O/S – runs on a main controlling computer (server) and provides communication and routing services so that clients can share data, programs, etc

Page 53: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

QUESTIONS ?

Page 54: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

A’ Level ComputingBy

P.M. Heathcote and S. Langfield

Pages 284 – 286, 293

Text :

Page 55: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

QUESTION

In a batch programming environment, the following 3 programs are ready to run: a payroll program, a complicated scientific calculation and the printing of a long queue of reports

i. Explain one reason for giving the queue of reports the highest priority

ii. Explain one reason why the scientific calculation should be given the lowest priority

Page 56: PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System.

THE END