9691 Computing

25
Compiled by: Mr. Benjamin Muganzi 9691 Computing Paper 3 Section 3.1 The functions of Operating Systems

description

9691 Computing. Paper 3 Section 3.1 The functions of Operating Systems. Functions of Operating Systems (OS). All Operating Systems (OS) have three main functions: Controlling and Managing Hardware Providing An Interface (Human-Machine and Machine-Software) - PowerPoint PPT Presentation

Transcript of 9691 Computing

Page 1: 9691 Computing

Compiled by: Mr. Benjamin Muganzi

9691 Computing

Paper 3Section 3.1

The functions of Operating Systems

Page 2: 9691 Computing

Compiled by: Mr. Benjamin Muganzi

VCN ICT Department 2013 2

Functions of Operating Systems (OS) All Operating Systems (OS) have three main functions:

Controlling and Managing Hardware Providing An Interface (Human-Machine and Machine-Software) Facilitating Application Software To Run

Operating systems must: Provide and manage hardware resources Provide an interface between the user and the machine Provide an interface between application software and the

machine Provide security for data on the system Provide utility software to allow maintenance to be done

Page 3: 9691 Computing

Compiled by: Mr. Benjamin Muganzi

VCN ICT Department 2013 3

Features of OS1. User interface: the two main types of user interfaces

are command line and graphical user interface.2. Device drivers (Routines which control hardware).

Example: Keyboard driver3. Multitasking capability which enables the computer

to run more than one program at one time. (Example: Running a word processing program, spreadsheet program and a database program at the same time in the computer.)

4. Spooling: directs jobs and data files to a queue on a backing store before sending them to their intended peripheral device.

Page 4: 9691 Computing

Compiled by: Mr. Benjamin Muganzi

VCN ICT Department 2013 4

Features of OS (continued)

5. Security: ensures that users can keep their files confidential

6. Scheduler: allocates job priorities and find and resolve deadlocks using scheduling algorithms

7. Memory manager: allocates memory to jobs and data8. Interrupt handler: routine in the operating system

which puts interrupts in a queue until they are processed by the processor.

9. Translators: converts source code of application programs into object code or to machine code

Page 5: 9691 Computing

Compiled by: Mr. Benjamin Muganzi

VCN ICT Department 2013 5

Interrupts An interrupt is a signal from a hardware device or an instruction

from a software program indicating the processor the need for a change in execution.

The processor processes program instructions stored in the memory. It fetches instructions one after the other and executes them.

If a problem occurs (anywhere in the system) while the processor is busy processing, the processor must respond to the problem as soon as possible in order to avoid damage to data and/or hardware.

This requires the processor to stop whatever it is doing and give its attention to the problem.

The device (hardware) or software, where the problem has occurred generates a signal, called an “interrupt” to get processor’s attention.

This is a simple method a computer uses to carry

out instructions.

Page 6: 9691 Computing

Compiled by: Mr. Benjamin Muganzi

Types of Interrupt

• I/O interrupt– Generated by an I/O device to signal that a job is

complete or an error has occurred. • E.g.

– Printer is out of paper or is not connected.

• Timer interrupt– Generated at fixed intervals.– Allows for display refresh and to control access to

processor in multi-access or multi-programming system.

Page 7: 9691 Computing

Compiled by: Mr. Benjamin Muganzi

Types of Interrupt • Hardware interrupt– E.g. • Power failure which indicates that the OS must close

down as safely as possible.• Program interrupt– Generated due to an error in a program such as

violation of memory use (trying to use part of the memory reserved by the OS for other use) or an attempt to execute an invalid instruction (such as division by zero).

Page 8: 9691 Computing

Compiled by: Mr. Benjamin Muganzi

VCN ICT Department 2013 8

Types of Interrupts (Summary)• Hardware: Generated by hardware devices. (Hardware

failure. Hardware going off-line)

• Software: Generated by software applications. (Violation of memory space. Virus found, division by zero)

• Timer: Generated by internal clock. (Scheduling of processes; an event is due)

• I/O: Generated by an I/O device. (e.g Printer out of paper; CD copying completed)

Page 9: 9691 Computing

Compiled by: Mr. Benjamin Muganzi

VCN ICT Department 2013 9

Managing interrupts• After execution of an

instruction, the processor must see if an interrupt has occurred.

• If yes, the OS services that interrupt following a new set of instructions.

Page 10: 9691 Computing

Compiled by: Mr. Benjamin Muganzi

VCN ICT Department 2013 10

What happens if the current job is more important than the

interrupt?• The Priority of the interrupt is compared with

current job.– If higher:• An appropriate interrupt service routine (ISR),

depending on the interrupt's importance, is loaded and run. • The Interrupt is serviced by the processor.

– If lower:• The interrupt is placed in a queue.• The current job continues with next cycle.

Page 11: 9691 Computing

Compiled by: Mr. Benjamin Muganzi

VCN ICT Department 2013 11

Resuming an interrupted program from where it left off after

interrupt has been Serviced

• The state of the current job is saved.

• This is done by saving the contents of all the registers in the processor so that the OS can use them to service the interrupt.

• The OS can load the register contents back in the registers to resume the job being interrupted once the interrupt has been serviced

Page 12: 9691 Computing

Compiled by: Mr. Benjamin Muganzi

VCN ICT Department 2013 12

What happens if several interrupts occur at the same time?

• Place the interrupts in a queue and only allow return to the originally interrupted program when the queue is empty.

• However, if an interrupt is considered important enough then an interrupt service routine (ISR) is chosen, which will “mask” the interrupt, meaning that any future interrupts are not considered until the current interrupt is completed.

Page 13: 9691 Computing

Compiled by: Mr. Benjamin Muganzi

VCN ICT Department 2013 13

What happens if some interrupts are more important

than others?• The Interrupt is

allocated a position in the job queue according to priorities.

– How this priority is decided is called scheduling

Page 14: 9691 Computing

Compiled by: Mr. Benjamin Muganzi

Handling Interrupts - Summary• The Current cycle is completed• Then the priority of interrupt is compared with the

current job• If higher:– Contents of special registers are saved, the current job is

allocated a position in the job queue according to priorities– Interrupt is serviced by OS.– On completion, values of special registers from original

program are loaded and the original job is restored.• If lower:– Interrupt is allocated a position in the job queue according

to priorities.– Current job continues with next cycle.

Page 15: 9691 Computing

Compiled by: Mr. Benjamin Muganzi

VCN ICT Department 2013 15

JOB SCHEDULING• Scheduling is an OS process that starts and ends tasks

(programs), manages concurrently running processes, and allocates system resources.

REASONS FOR SCHEDULING Maximize the use of the whole of the computer system Be fair to all users Provide a reasonable response time to all users, whether they

are on-line users or a batch processing user Prevent the system failing if it is becoming overloaded Make sure that the system is consistent by always giving similar

response times to similar activities from day to day

Page 16: 9691 Computing

Compiled by: Mr. Benjamin Muganzi

VCN ICT Department 2013 16

Input Output (I/O) bound Vs Processor bound jobs

• I/O bound jobs are those that require relatively little processing but do need to use the peripheral devices substantially.

– E.g. Printing wage slips for the employees of a large company

• Processor bound jobs are those that require a large amount of processor time and very little use of the various peripheral devices. – E.g. Analysing the annual, world-wide sales of the company

which has a turnover of many billions of Shillings.

Page 17: 9691 Computing

Compiled by: Mr. Benjamin Muganzi

VCN ICT Department 2013 17

• Job A is processor-bound and Job B is I/O bound.

• I/O bound jobs are given more time in order to allow them to finish in reasonable time.

• Processor bound jobs are given lesser time as they can do more in less time and shouldn’t hold the I/O bound jobs.

Scheduling Example

Page 18: 9691 Computing

Compiled by: Mr. Benjamin Muganzi

VCN ICT Department 2013 18

STRATEGIES FOR SCHEDULING• Scheduling of processes requires careful considerations. The

following are the most common:

Priority: Giving some jobs priority over others. I/O or Processor Bound: Deciding which job is processor bound and which is

I/O bound. Type of Job: Batch processing, on-line and real-time jobs all require

different response times. Resource Requirements: The amount of time needed to complete the job,

the memory required, I/O and processor time. Resources Used So Far: The amount of processor time used so far, how

much I/O used so far. Waiting Time: The time the job has been waiting to use the system.

Page 19: 9691 Computing

Compiled by: Mr. Benjamin Muganzi

VCN ICT Department 2013 19

Process handling• A job can be in any of the

following states.

– Ready [Ready to start]– Running [on the system]– Blocked [Waiting for a

peripheral]• A job can only enter the running state from the ready state. • The ready and blocked states are queues that may hold several jobs. • On a standard single processor computer only one job can be in the

running state. • All jobs entering the system normally enter via the ready state and

(normally) only leave the system from the running state.

NO

TE

Page 20: 9691 Computing

Compiled by: Mr. Benjamin Muganzi

VCN ICT Department 2013 20

Schedulers• High Level Scheduler (HLS) is responsible for

placing a job in the ready queue. The HLS makes sure that the system is not over loaded.

• Mid-Level Scheduler (MLS) is responsible for swapping jobs between main and secondary memory.

• Low-Level Scheduler (LLS) is responsible for Moving jobs in and out of the ready state.– The LLS decides the order in which jobs are to be

placed in the running state.

Page 21: 9691 Computing

Compiled by: Mr. Benjamin Muganzi

VCN ICT Department 2013 21

Scheduling policies

• There are many policies that may be used to do scheduling, but they can all be placed in one of two classes. These are pre-emptive and non-pre-emptive policies.

• Pre-emptive policy: allows the LLS to put or remove jobs from the RUNNING queue as and when needed.

• Non Pre-emptive policy allows jobs to run until they no longer need the processor.

Page 22: 9691 Computing

Compiled by: Mr. Benjamin Muganzi

VCN ICT Department 2013 22

Common scheduling algorithms• First come first Served (FCFS): Simply means that the first job to enter the ready

queue is the first to enter the running state. This favors long jobs. (Non pre-emptive by design)

• Shortest Job first (SJF): Simply means sort jobs in the ready queue in ascending order of times expected to be needed by each job. New jobs are added to the queue in such a way as to preserve this order. (Non pre-emptive)

• Round Robin (RR): This gives each job a maximum length of processor time (called a time slice) after which the job is put at the back of the ready queue and the job at the front of the queue is given use of the processor. If a job is completed before the maximum time is up it leaves the system.

• Shortest Remaining Time (SRT): The ready queue is sorted on the amount of expected time still required by a job. This scheme favours short jobs even more than SJF. Also there is a danger of long jobs being prevented from running.

• Priority Queues (PQ): Priority Queues involve queues of different priorities. Jobs in higher priority queues are executed first.

• Multi-level Feedback queues (MFQ): Involves several queues of different priorities with jobs migrating downwards.

Page 23: 9691 Computing

Compiled by: Mr. Benjamin Muganzi

Other methods of allocating priorities:

All the policies discussed on previous slides are methods of allocating priorities. Here are some others:

• Amount of time already waited.• Amount of processor time already given.• Amount of peripheral time.– Compares I/O jobs and asks “How much of a I/O job are

you?”• Necessary response time.– Compares real-time / on-line jobs and asks “How much of

a real-time / on-line jobs are you?” or “OK, you are a real-time / on-line job but how quickly do I need to respond to you?”

Page 24: 9691 Computing

Compiled by: Mr. Benjamin Muganzi

VCN ICT Department 2013 24

Other methods of allocating priorities:• Importance of Job / Type of Job

– Safety critical jobs will be given very high priority, on-line and real time applications will also have to have high priorities.• E.g. 1. A computer monitoring the temperature and pressure in a chemical

process whilst analysing results of readings taken over a period of time must give the high priority to the control program. – If the temperature or pressure goes out of a pre-defined range,

the control program must take over immediately. 2. A bank's computer is printing bank statements over night and

someone wishes to use a cash point, the cash point job must take priority.

– Also remember I/O bound jobs will also get priority as stated earlier.

– Can be Pre-Emptive or Non-Pre-Emptive depending on if the queue is checked after each cycle or not.

Page 25: 9691 Computing

Compiled by: Mr. Benjamin Muganzi

VCN ICT Department 2013 25

Memory Management• Memory Management is the process of

managing jobs and their data in the memory.

When a job needs to be processed, it is stored in the main memory along with its data.

The job’s code and data must be managed and protected from actions of other other.

In most of the modern OS, more than one job can be loaded into the memory at one time.