Lecture – 1 by: Nidal Seerat

87
Lecture – 1 By: NIDAL SEERAT 1 O.S Lecture 1

Transcript of Lecture – 1 by: Nidal Seerat

Page 1: Lecture – 1 by: Nidal Seerat

Lecture – 1

By: NIDAL SEERAT

1O.S Lecture 1

Page 2: Lecture – 1 by: Nidal Seerat

O.S Lecture 1 2

Page 3: Lecture – 1 by: Nidal Seerat

Operating SystemA program that controls the execution of application

programs ORAn interface between applications and hardware

ORA program that acts as an intermediary between a

user of a computer and the computer hardware.Operating system goals:

Execute user programs and make solving user problems easier.

Make the computer system convenient to use.Use the computer hardware in an efficient manner.

3O.S Lecture 1

Page 4: Lecture – 1 by: Nidal Seerat

Operating SystemFunctions same way as ordinary computer software

It is program that is executedOperating system relinquishes control of the

processor to execute other programs

4O.S Lecture 1

Page 5: Lecture – 1 by: Nidal Seerat

Basic Elements of OSProcessorMain Memory

referred to as real memory or primary memoryvolatile

I/O modulessecondary memory devicescommunications equipmentterminals

System buscommunication among processors, memory, and I/O

modules

5O.S Lecture 1

Page 6: Lecture – 1 by: Nidal Seerat

Operating System ObjectivesConvenience

Makes the computer more convenient to useEfficiency

Allows computer system resources to be used in an efficient manner

Ability to evolvePermit effective development, testing, and introduction

of new system functions without interfering with service

6O.S Lecture 1

Page 7: Lecture – 1 by: Nidal Seerat

Layers of Computer System

7O.S Lecture 1

Page 8: Lecture – 1 by: Nidal Seerat

Services Provided by the Operating System1. Program development

Editors and debuggers2. Program execution3. Access to I/O devices4. Controlled access to files5. System access6. Error detection and response

internal and external hardware errors memory error device failure

software errors arithmetic overflow access forbidden memory locations

8O.S Lecture 1

Page 9: Lecture – 1 by: Nidal Seerat

Services Provided by the Operating System7. Accounting

collect statisticsmonitor performanceused to anticipate future enhancementsused for billing users

9O.S Lecture 1

Page 10: Lecture – 1 by: Nidal Seerat

Operating System RolesResource allocator – manages and allocates

resource. Performs Job scheduling & CPU scheduling.

Control program – controls the execution of user programs and operations of I/O devices

Kernel – the one program running at all times (all else being application programs).

10O.S Lecture 1

Page 11: Lecture – 1 by: Nidal Seerat

Reasons for Evolution of an Operating SystemHardware upgrades and new types of hardwareNew servicesFixes

11O.S Lecture 1

Page 12: Lecture – 1 by: Nidal Seerat

O.S Lecture 1 12

Page 13: Lecture – 1 by: Nidal Seerat

Evolution of Operating SystemsSerial Processing

No operating systemMachines run from a console with display lights and

toggle switches, input device, and printerIn case of error ,Programmer had to examine registers

& main memory to detect source of error.Setup included loading the compiler, source program

(in Assembly language), saving compiled program, and loading and linking common functions.

13O.S Lecture 1

Page 14: Lecture – 1 by: Nidal Seerat

Problems in Serial ProcessingScheduling

User may sign-up for 1 hour and may finish the job in 45 minutes, result in wasted CPU cycles.

Setup timeSetup included loading the compiler, source program

(in Assembly language), saving compiled program, and loading and linking common functions.

Require mounting & dismounting of tapes.

O.S Lecture 1 14

Page 15: Lecture – 1 by: Nidal Seerat

Evolution of Operating SystemsSimple Batch Systems

Monitors Software that controls the running programs Batch jobs together Program branches back to monitor when finished Resident monitor is in main memory and available for execution Handled job scheduling & job setup time by attaching setup

instruction to each job.

Job Control Language (JCL) Special type of programming language Provides instruction to the monitor

what compiler to use what data to use

15O.S Lecture 1

Page 16: Lecture – 1 by: Nidal Seerat

Ctd…..Simple batch systemsHardware Features

Memory protection do not allow the memory area containing the monitor to be

altered Report error if a job is trying to access monitor’s memory area

Timer prevents a job from monopolizing the system If time expires ,return the control to monitor

Privileged Instructions Only executed by monitor If such instruction comes,job execution stops I/O requests are example.

16O.S Lecture 1

Page 17: Lecture – 1 by: Nidal Seerat

17O.S Lecture 1

Page 18: Lecture – 1 by: Nidal Seerat

Disadvantages of Simple batch systemsUni-programmingCPU cycles wasted due to I/O requestsJob execution in sequence

O.S Lecture 1 18

Page 19: Lecture – 1 by: Nidal Seerat

Multiprogrammed batch systemsWhen one program waits for I/O, the CPU switch to

next job.Several programs in memory at a time.Supported I/O interrupt mechanismDisadvantages:

No User InterfaceTransaction Processing systems needs interactive user

interface

O.S Lecture 1 19

Page 20: Lecture – 1 by: Nidal Seerat

Mainframe SystemsReduce setup time by batching similar jobsAutomatic job sequencing – automatically

transfers control from one job to another. First rudimentary operating system.Resident monitor

initial control in monitor control transfers to job when job completes control transfers pack to

monitor

20O.S Lecture 1

Page 21: Lecture – 1 by: Nidal Seerat

Several jobs are kept in main memory at the same time, and the CPU is multiplexed among them.

21O.S Lecture 1

Page 22: Lecture – 1 by: Nidal Seerat

UniprogrammingProcessor must wait for I/O instruction to complete

before preceding

22O.S Lecture 1

Page 23: Lecture – 1 by: Nidal Seerat

MultiprogrammingWhen one job needs to wait for I/O, the processor

can switch to the other job

23O.S Lecture 1

Page 24: Lecture – 1 by: Nidal Seerat

Multiprogramming Systems

24O.S Lecture 1

Page 25: Lecture – 1 by: Nidal Seerat

Effects of Multiprogramming

Uniprogramming Multiprogramming

Processor use 22% 43%

Memory use 30% 67%

Disk use 33% 67%

Printer use 33% 67%

Elapsed time 30 min. 15 min.

Throughput rate 6 jobs/hr 12 jobs/hr

Mean response time 18 min. 10 min.

25O.S Lecture 1

Page 26: Lecture – 1 by: Nidal Seerat

Time Sharing Systems……..interactive computingUsing multiprogramming to handle multiple interactive jobs

Processor’s time is shared among multiple users

Multiple users simultaneously access the system through terminals

The CPU is multiplexed among several jobs that are kept in memory

and on disk (the CPU is allocated to a job only if the job is in memory).

A job swapped in and out of memory to the disk.

On-line communication between the user and the system is provided;

when the operating system finishes the execution of one command, it

seeks the next “control statement” from the user’s keyboard.

On-line system must be available for users to access data and code.26O.S Lecture 1

Page 27: Lecture – 1 by: Nidal Seerat

Batch Multiprogramming versus Time Sharing

Batch Multiprogramming Time Sharing

Principal objective Maximize processor use Minimize response time

Source of directives to operating system

Job control language commands provided with the job

Commands entered at the terminal

27O.S Lecture 1

Page 28: Lecture – 1 by: Nidal Seerat

Desktop SystemsPersonal computers – computer system

dedicated to a single user.I/O devices – keyboards, mice, display screens,

small printers.User convenience and responsiveness.Can adopt technology developed for larger

operating system’ often individuals have sole use of computer and do not need advanced CPU utilization of protection features.

May run several different types of operating systems (Windows, MacOS, UNIX, Linux)

28O.S Lecture 1

Page 29: Lecture – 1 by: Nidal Seerat

Parallel SystemsMultiprocessor systems with more than on CPU in

close communication.Tightly coupled system – processors share memory

and a clock; communication usually takes place through the shared memory.

Advantages of parallel system: Increased throughputEconomical Increased reliability

graceful degradation fail-soft systems

29O.S Lecture 1

Page 30: Lecture – 1 by: Nidal Seerat

Parallel Systems (Cont.)Symmetric multiprocessing (SMP)

Each processor runs and identical copy of the operating system.

Many processes can run at once without performance deterioration.

Most modern operating systems support SMPAsymmetric multiprocessing

Each processor is assigned a specific task; master processor schedules and allocated work to slave processors.

More common in extremely large systems

30O.S Lecture 1

Page 31: Lecture – 1 by: Nidal Seerat

31O.S Lecture 1

Page 32: Lecture – 1 by: Nidal Seerat

Distributed SystemsDistribute the computation among several

physical processors.Loosely coupled system – each processor has

its own local memory; processors communicate with one another through various communications lines, such as high-speed buses or telephone lines.

Advantages of distributed systems.Resources Sharing Computation speed up – load sharing ReliabilityCommunications

32O.S Lecture 1

Page 33: Lecture – 1 by: Nidal Seerat

O.S Lecture 1

Distributed Systems (cont)

Requires networking infrastructure.Local area networks (LAN) or Wide area

networks (WAN)May be either client-server or peer-to-peer

systems.

33

Page 34: Lecture – 1 by: Nidal Seerat

O.S Lecture 1 34

Page 35: Lecture – 1 by: Nidal Seerat

O.S Lecture 1

Clustered SystemsClustering allows two or more systems to share

storage.Provides high reliability.Asymmetric clustering: one server runs the

application while other servers standby.Symmetric clustering: all N hosts are running the

application.

35

Page 36: Lecture – 1 by: Nidal Seerat

O.S Lecture 1

Real-Time SystemsOften used as a control device in a dedicated

application such as controlling scientific experiments, medical imaging systems, industrial control systems, and some display systems.

Well-defined fixed-time constraints.

36

Page 37: Lecture – 1 by: Nidal Seerat

O.S Lecture 1

Handheld SystemsPersonal Digital Assistants (PDAs)Cellular telephonesIssues:

Limited memorySlow processorsSmall display screens.

37

Page 38: Lecture – 1 by: Nidal Seerat

Major AchievementsProcessesMemory ManagementInformation protection and securityScheduling and resource managementSystem structure

38O.S Lecture 1

Page 39: Lecture – 1 by: Nidal Seerat

O.S Lecture 1 39

Page 40: Lecture – 1 by: Nidal Seerat

Computer System Components1. Hardware – provides basic computing resources

(CPU, memory, I/O devices).

2. Operating system – controls and coordinates the use of the hardware among the various application programs for the various users.

3. Applications programs – define the ways in which the system resources are used to solve the computing problems of the users (compilers, database systems, video games, business programs).

4. Users (people, machines, other computers).

40O.S Lecture 1

Page 41: Lecture – 1 by: Nidal Seerat

41O.S Lecture 1

Page 42: Lecture – 1 by: Nidal Seerat

O.S Lecture 1

Computer-System OperationI/O devices and the CPU can execute concurrently.Each device controller is in charge of a particular

device type.Each device controller has a local buffer.CPU moves data from/to main memory to/from local

buffersI/O is from the device to local buffer of controller.Device controller informs CPU that it has finished its

operation by causing an interrupt.

42

Page 43: Lecture – 1 by: Nidal Seerat

43O.S Lecture 1

Page 44: Lecture – 1 by: Nidal Seerat

Instruction Cycle

44O.S Lecture 1

Page 45: Lecture – 1 by: Nidal Seerat

Instruction Fetch and Execute1. The processor fetches the instruction from memory

2. Program counter (PC) holds address of the instruction to be fetched next

3. Program counter is incremented after each fetch

4. Fetched instruction is loaded into CPU’s instruction registers .

5. CPU reads & executes instruction.

6. increments PC

45O.S Lecture 1

Page 46: Lecture – 1 by: Nidal Seerat

Interrupts

O.S Lecture 1 46

An interrupt is an asynchronous signal from hardware indicating need for attention

OR

it is synchronous event in software indicating the need for a change in execution.

Page 47: Lecture – 1 by: Nidal Seerat

InterruptsIt is an interruption of the normal sequence of execution.An act of interrupting is called IRQ (interrupt request).Bus lines are used to signal an interrupt.Hardware interrupt:

Causes CPU to save its state of execution via context switch & begin execution of an interrupt handler.

Software interrupt:Are usually implemented as instruction in instruction set

which cause context switch to an interrupt handler.

O.S Lecture 1 47

Page 48: Lecture – 1 by: Nidal Seerat

Advantages of Interrupts

It is common technique for computer multi-tasking in real time computing.

Improves processing efficiency.Helps O.S by reducing time spent in in waiting for

I/O devices to complete their task.Allows the processor to execute other instructions

while an I/O operation is in progressA process is suspended in such a way that it can

be resumed later.

48O.S Lecture 1

Page 49: Lecture – 1 by: Nidal Seerat

O.S Lecture 1

Common Functions of InterruptsInterrupt transfers control to the interrupt service

routine generally, through the interrupt vector, which contains the addresses of all the service routines.

Interrupt architecture must save the address of the interrupted instruction.

Incoming interrupts are disabled while another interrupt is being processed to prevent a lost interrupt.

A trap is a software-generated interrupt caused either by an error or a user request.

An operating system is interrupt driven.

49

Page 50: Lecture – 1 by: Nidal Seerat

Classes of InterruptsProgram

arithmetic overflowdivision by zeroexecute illegal instructionreference outside user’s memory space

TimerI/OHardware failure

50O.S Lecture 1

Page 51: Lecture – 1 by: Nidal Seerat

Interrupt HandlerA program that determines nature of the interrupt and

performs whatever actions are neededControl is transferred to handlerGenerally it’s a part of the operating system

51O.S Lecture 1

Page 52: Lecture – 1 by: Nidal Seerat

O.S Lecture 1

Interrupt HandlingThe operating system preserves the state of the CPU

by storing registers and the program counter.Determines which type of interrupt has occurred:

pollingvectored interrupt system

Separate segments of code determine what action should be taken for each type of interrupt

52

Page 53: Lecture – 1 by: Nidal Seerat

Interrupt Cycle

53O.S Lecture 1

Page 54: Lecture – 1 by: Nidal Seerat

Interrupt Cycle1. With interrupts, CPU can also execute other

instructions while an I/O is in progress.

2. After execution of each instruction, Processor checks for interrupts.

3. If no interrupts fetch the next instruction for the current program

4. If an interrupt is pending, suspend execution of the current program, and execute the interrupt handler

54O.S Lecture 1

Page 55: Lecture – 1 by: Nidal Seerat

Multiple Interrupts1. Sequential OrderDisable interrupts so processor can complete taskInterrupts remain pending until the processor enables

interruptsAfter interrupt handler routine completes, the

processor checks for additional interrupts

55O.S Lecture 1

Page 56: Lecture – 1 by: Nidal Seerat

Multiple Interrupts2. Priorities

Higher priority interrupts cause lower-priority interrupts to wait

Causes a lower-priority interrupt handler to be interrupted

Example when input arrives from communication line, it needs to be absorbed quickly to make room for more input

56O.S Lecture 1

Page 57: Lecture – 1 by: Nidal Seerat

I/O Structure

O.S Lecture 1 57

Page 58: Lecture – 1 by: Nidal Seerat

I/O StructureAfter I/O starts, control returns to user program only upon

I/O completion.Wait instruction idles the CPU until the next interruptWait loop (contention for memory access).At most one I/O request is outstanding at a time, no simultaneous

I/O processing.

After I/O starts, control returns to user program without waiting for I/O completion.System call – request to the operating system to allow user to

wait for I/O completion.Device-status table contains entry for each I/O device indicating

its type, address, and state.Operating system indexes into I/O device table to determine

device status and to modify table entry to include interrupt.

58O.S Lecture 1

Page 59: Lecture – 1 by: Nidal Seerat

Synchronous Asynchronous

59

Page 60: Lecture – 1 by: Nidal Seerat

Programmed I/OSynchronous typeI/O module performs the action, not

the processorSets appropriate bits in the I/O status

registerNo interrupts occurProcessor checks status until

operation is complete

60O.S Lecture 1

Page 61: Lecture – 1 by: Nidal Seerat

Interrupt-Driven I/OAsynchronous typeProcessor is interrupted when I/O

module ready to exchange dataProcessor is free to do other workNo needless waitingConsumes a lot of processor time

because every word read or written passes through the processor

61O.S Lecture 1

Page 62: Lecture – 1 by: Nidal Seerat

Direct Memory Access (DMA)Used for high-speed I/O devices able to transmit

information at close to memory speeds.I/O exchanges occur directly with memoryDevice controller transfers blocks of data from buffer

storage directly to main memory without CPU intervention.Only one interrupt is generated per block, rather than the

one interrupt per byte.Processor grants I/O module authority to read from or

write to memoryRelieves the processor responsibility for the exchangeProcessor is free to do other things

62O.S Lecture 1

Page 63: Lecture – 1 by: Nidal Seerat

Direct Memory AccessTransfers a block of data

directly to or from memoryAn interrupt is sent when the

task is completeThe processor is only involved

at the beginning and end of the transfer

63O.S Lecture 1

Page 64: Lecture – 1 by: Nidal Seerat

Kernel

O.S Lecture 1 64

Page 65: Lecture – 1 by: Nidal Seerat

O.S Lecture 1 65

Page 66: Lecture – 1 by: Nidal Seerat

Kernel

O.S Lecture 1 66

Page 67: Lecture – 1 by: Nidal Seerat

KernelA portion of O.S is always in the main memory, which

is called Kernel or Nucleus. It contains most frequently used functions and currently used part of the O.S and memory management.

It is a basic software component of an O.S responsible for providing secure access to machine’s hardware to various computer programs.

It provides low level abstraction layer for the resources (such as memory, CPU & i/o devices) that application software needs to perform its functions.

Kernel also decides when & how long a program will use any hardware.

67O.S Lecture 1

Page 68: Lecture – 1 by: Nidal Seerat

Kernel

O.S Lecture 1 68

Page 69: Lecture – 1 by: Nidal Seerat

ctd……..Kernel It make facilities available to application processes through IPC & system calls.

It is always awake but dormant in the memory. It never sleeps.

The “Boot Loader” starts executing the kernel then kernel initializes itself and starts

the first process.

After this, kernel does not execute directly and only response to system calls(by

software) and interrupts (by hardware) to notify the events to kernel.

Kernel has most frequently used functions.

Basic facilities of kernel are:

Process management

Memory management

Device management

Systems Calls

O.S Lecture 1 69

Page 70: Lecture – 1 by: Nidal Seerat

O.S Lecture 1 70

Page 71: Lecture – 1 by: Nidal Seerat

Common O.S Components

Process Management Main Memory ManagementFile ManagementI/O System ManagementSecondary ManagementNetworkingProtection SystemCommand-Interpreter System

71O.S Lecture 1

Page 72: Lecture – 1 by: Nidal Seerat

Process ManagementA process is a program in execution. A process

needs certain resources, including CPU time, memory, files, and I/O devices, to accomplish its task.

The operating system is responsible for the following activities in connection with process management.Process creation and deletion.process suspension and resumption.Provision of mechanisms for:

process synchronization process communication

72O.S Lecture 1

Page 73: Lecture – 1 by: Nidal Seerat

Main-Memory Management

Memory is a large array of words or bytes, each with its own address. It is a repository of quickly accessible data shared by the CPU and I/O devices.

Main memory is a volatile storage device. It loses its contents in the case of system failure.

The operating system is responsible for the following activities in connections with memory management:Keep track of which parts of memory are currently

being used and by whom.Decide which processes to load when memory

space becomes available.Allocate and de-allocate memory space as needed.

73O.S Lecture 1

Page 74: Lecture – 1 by: Nidal Seerat

File ManagementA file is a collection of related information defined by

its creator. Commonly, files represent programs (both source and object forms) and data.

The operating system is responsible for the following activities in connections with file management:File creation and deletion.Directory creation and deletion.Support of primitives for manipulating files and

directories.Mapping files onto secondary storage.File backup on stable (nonvolatile) storage media.

74O.S Lecture 1

Page 75: Lecture – 1 by: Nidal Seerat

I/O System Management

The I/O system consists of:A buffer-caching system A general device-driver interfaceDrivers for specific hardware devices

75O.S Lecture 1

Page 76: Lecture – 1 by: Nidal Seerat

Secondary-Storage ManagementSince main memory (primary storage) is volatile and

too small to accommodate all data and programs permanently, the computer system must provide secondary storage to back up main memory.

Most modern computer systems use disks as the principle on-line storage medium, for both programs and data.

The operating system is responsible for the following activities in connection with disk management: Free space managementStorage allocationDisk scheduling

76

Page 77: Lecture – 1 by: Nidal Seerat

Networking (Distributed Systems)A distributed system is a collection processors that do not

share memory or a clock. Each processor has its own local memory.

The processors in the system are connected through a communication network.

Communication takes place using a protocol.A distributed system provides user access to various

system resources.Access to a shared resource allows:

Computation speed-up Increased data availabilityEnhanced reliability

77O.S Lecture 1

Page 78: Lecture – 1 by: Nidal Seerat

Protection SystemProtection refers to a mechanism for controlling

access by programs, processes, or users to both system and user resources.

The protection mechanism must: distinguish between authorized and unauthorized

usage.specify the controls to be imposed.provide a means of enforcement.

78O.S Lecture 1

Page 79: Lecture – 1 by: Nidal Seerat

Command-Interpreter SystemMany commands are given to the operating system

by control statements which deal with:process creation and managementI/O handlingsecondary-storage managementmain-memory managementfile-system access protection networking

79O.S Lecture 1

Page 80: Lecture – 1 by: Nidal Seerat

Command-Interpreter System (Cont.)The program that reads and interprets control

statements is called variously:

command-line interpretershell (in UNIX)

Its function is to get and execute the next command statement.

80O.S Lecture 1

Page 81: Lecture – 1 by: Nidal Seerat

O.S Lecture 1 81

System CallsSystem calls provide the interface between a running program and

the operating system.Generally available as assembly-language instructions.Languages defined to replace assembly language for systems

programming allow system calls to be made directly (e.g., C, C++)

Three general methods are used to pass parameters between a running program and the operating system.Pass parameters in registers.Store the parameters in a table in memory, and the table address

is passed as a parameter in a register. (used by Linux)Push (store) the parameters onto the stack by the program, and

pop off the stack by operating system.

Page 82: Lecture – 1 by: Nidal Seerat

O.S Lecture 1 82

Types of System CallsProcess control

end ,abort , load, execute, create & terminate proceess fork() ,wait,get & set process attributes

File managementCreate & delete file, open & close file, read,write

Device management Request,release,read,write device

Information maintenanceGet/set date & time, get/set process/file/device attributes

CommunicationsCreate/delete comm connection,sen/receive msg,transfer

status info,attach/detach remote devices

Page 83: Lecture – 1 by: Nidal Seerat

O.S Lecture 1 83

Message Passing Shared Memory

Communication may take place using either message passing or shared memory.

Page 84: Lecture – 1 by: Nidal Seerat

O.S Lecture 1 84

Virtual Machinesvirtual machine (VM) is a software implementation

of a machine (computer) that executes programs like a real machine.

A virtual machine takes the layered approach to its logical conclusion.

It treats hardware and the operating system kernel as though they were all hardware.

A virtual machine provides an interface identical to the underlying bare hardware.

The operating system creates the illusion of multiple processes, each executing on its own processor with its own (virtual) memory.

Page 85: Lecture – 1 by: Nidal Seerat

O.S Lecture 1 85

Virtual Machines (Cont.)The resources of the physical computer are shared to

create the virtual machines.CPU scheduling can create the appearance that users

have their own processor.Spooling and a file system can provide virtual card

readers and virtual line printers.A normal user time-sharing terminal serves as the

virtual machine operator’s console.

Page 86: Lecture – 1 by: Nidal Seerat

O.S Lecture 1 86

Non-virtual Machine Virtual Machine

Page 87: Lecture – 1 by: Nidal Seerat

O.S Lecture 1 87

Advantages/Disadvantages of Virtual Machines

The virtual-machine concept provides complete protection of system

resources since each virtual machine is isolated from all other virtual

machines. This isolation, however, permits no direct sharing of

resources.

A virtual-machine system is a perfect vehicle for operating-systems

research and development. System development is done on the virtual

machine, instead of on a physical machine and so does not disrupt

normal system operation.

The virtual machine concept is difficult to implement due to the effort

required to provide an exact duplicate to the underlying machine.