1 of 50

���Operating Systems

Department of BCA

Loyola college of arts and science

Mettala

2 of 50

Chapter 1:

Introduction

OS Notes by Dr. Naveen Choudhary

  • What is an Operating System?
  • Mainframe Systems
  • Desktop Systems
  • Multiprocessor Systems
  • Distributed Systems
  • Clustered System
  • Real -Time Systems
  • Handheld Systems
  • Computing Environments

3 of 50

What is an Operating System?

OS Notes by Dr. Naveen Choudhary

  • A 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.

  • Basically OS is a
    • Resource manager with objective of efficient resource use and user convenience
    • Control program that controls the execution of user programs to

prevent errors and improper use of the computer

4 of 50

Computer System Components

OS Notes by Dr. Naveen Choudhary

  1. Hardware – provides basic computing resources (CPU,

memory, I/O devices).

  1. Operating system – controls and coordinates the use of the hardware among the various application/system programs for the various users.
  2. Applications/system 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).
  3. Users (people, machines, other computers).

5 of 50

Abstract View of System Components

OS Notes by Dr. Naveen Choudhary

6 of 50

Operating System Definitions

OS Notes by Dr. Naveen Choudhary

  • Resource allocator – manages and allocates resources.
  • Control program – controls the execution of user programs and operations of I/O devices and handles errors
  • Kernel – the one program running at all times (all else

being application programs).

7 of 50

Computer startup

OS Notes by Dr. Naveen Choudhary

  • bootstrap program is loaded at power-up or reboot
    • Typically stored in ROM or EEPROM, generally known as

firmware

    • Initializates all aspects of system
    • Loads operating system kernel and starts execution

8 of 50

Mainframe Systems

OS Notes by Dr. Naveen Choudhary

  • In old days H/W used to be card readers, tape drives, line printers etc (ie basically slow devices as lot of mechanical parts are involved)
  • But CPU was relatively quite fast being an electronic device
  • So at this time interactive systems were not possible as they will slow down the execution dramatically because of slow I/O devices and so CPU will mostly be idle. And

that’s why we needed Batch Systems

  • Reduce setup time by batching similar requirement jobs
  • Automatic job sequencing – automatically transfers

control from one job to another.

  • Resident monitor
    • initial control in monitor
    • control transfers to job
    • when job completes control transfers back to monitor

9 of 50

Memory Layout for a Simple Batch System

OS Notes by Dr. Naveen Choudhary

10 of 50

Multiprogrammed Batch Systems

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

Initially used punched cards 🡪 data ,

program and control cards

Spooling (simultaneous peripheral operation online )🡪 Introduction of disk technology

🡪So cards can be read into disk for later cpu reading & cpu o/p for printing can also be put on disk for later printing

🡪So spooling can help overlap the i/o of

one job with the computation of the other.

OS Notes by Dr. Naveen Choudhary

11 of 50

OS Features Needed for Multiprogramming

OS Notes by Dr. Naveen Choudhary

  • I/O routine supplied by the system.
  • Memory management – the system must allocate the

memory to several jobs.

  • Job scheduling : choosing a job from many ready jobs on

disk to bring it to the memory

  • CPU scheduling – the system must choose among

several jobs ready to run.

  • Allocation of devices.

12 of 50

Time-Sharing Systems–Interactive Computing

OS Notes by Dr. Naveen Choudhary

  • The CPU is multiplexed among several jobs that are kept in memory (the CPU is allocated to a job only if the job is in memory).
  • A job can be swapped in and out of memory from/to the

disk.

  • With time sharing systems -- the interactive systems were possible. Each process was given small quantum of time

13 of 50

Multiprogramming/multitasking

OS Notes by Dr. Naveen Choudhary

  • Multiprogramming needed for efficiency
    • Single user cannot keep CPU and I/O devices busy at all times
    • Multiprogramming organizes jobs (code and data) so CPU always has one to execute
    • A subset of total jobs in system is kept in memory
    • One job selected and run via job scheduling
    • When it has to wait (for I/O for example), OS switches to another job
  • Timesharing (multitasking) is logical extension in which CPU switches jobs so frequently that users can interact with each job while it is running, creating interactive computing
    • Response time should be < 1 second
    • Each user has at least one program executing in memory 🢡process
    • If several jobs ready to run at the same time 🢡 CPU scheduling
    • If processes don’t fit in memory, swapping moves them in and out to run
    • Virtual memory allows execution of processes not completely in memory

14 of 50

Desktop Systems

OS Notes by Dr. Naveen Choudhary

  • Personal 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)

15 of 50

Parallel Systems

OS Notes by Dr. Naveen Choudhary

  • Multiprocessor systems with more than one 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 throughput :: as more processors so more work done per unit time🡪 but increase is not n (for n processors) as some time will be wasted in overheads and contention for shared resources.
    • Economical
    • Increased reliability

🗐 graceful degradation 🡪 fault tolerance

16 of 50

Parallel Systems (Cont.)

OS Notes by Dr. Naveen Choudhary

  • Symmetric multiprocessing (SMP)
    • Each processor runs and identical copy of the operating system and these can be communicated ( through shared memory as & when needed)
    • Many processes can run at once without performance

deterioration.

    • Most modern operating systems support SMP
  • Asymmetric multiprocessing
    • Each processor is assigned a specific task; master processor schedules and allocated work to slave processors.
    • More common in extremely large systems

17 of 50

Multiprocessing Architecture

OS Notes by Dr. Naveen Choudhary

18 of 50

Distributed Systems

OS Notes by Dr. Naveen Choudhary

  • Distribute 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
    • Reliability
    • Communications (ie exchange of information in form of mail,

file transfer is possible)

19 of 50

Distributed Systems (cont)

OS Notes by Dr. Naveen Choudhary

  • Requires networking infrastructure.
  • Local area networks (LAN) or Wide area networks (WAN)
  • May be either client-server or peer-to-peer systems.

20 of 50

General Structure of Client-Server

OS Notes by Dr. Naveen Choudhary

21 of 50

Real-Time Systems

OS Notes by Dr. Naveen Choudhary

  • Often 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.
  • Real-Time systems may be either hard or soft real-time.

22 of 50

Real-Time Systems (Cont.)

OS Notes by Dr. Naveen Choudhary

  • Hard real-time:
    • Secondary storage limited or absent, data stored in short term memory, or read-only memory (ROM)
    • Conflicts with time-sharing systems as no virtual memory.

  • Soft real-time
    • Limited utility in industrial control of robotics
    • Useful in applications (multimedia, virtual reality, undersea exploration, planetory rovers) requiring advanced operating- system features.
    • Ex. RT Linux

23 of 50

Chapter 2: Computer-System Structures

OS Notes by Dr. Naveen Choudhary

  • Computer System Operation
  • I/O Structure
  • Storage Structure
  • Storage Hierarchy
  • Hardware Protection
  • General System Architecture

24 of 50

Computer-System Architecture

Bootstrap:(1) Initialize h/w - like cpu registers, device controllers, memory controllers etc ( 2 ) Loads o.s kernel into the primary memory and then transfers control to O.S

OS Notes by Dr. Naveen Choudhary

25 of 50

Computer-System Operation

OS Notes by Dr. Naveen Choudhary

  • I/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 & a set of special

purpose registers

  • CPU loads the appropriate registers with in the device

controller ( say for some read operation )

  • I/O is from the device to local buffer of controller.
  • CPU moves data from/to main memory to/from local

buffers

  • Device controller informs CPU that it has finished its

operation by causing an interrupt.

26 of 50

Common Functions of Interrupts

OS Notes by Dr. Naveen Choudhary

  • Interrupt 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 (specifically when program counters and other registers are being saved )
  • A trap is a software-generated interrupt caused either by

an error or a user request.

  • An operating system is interrupt driven.

27 of 50

Interrupt Handling

OS Notes by Dr. Naveen Choudhary

  • The operating system preserves the state of the CPU by storing registers and the program counter. (disable further interrupts, while this is being done )
  • Separate segments of code determine what action should

be taken for each type of interrupt

28 of 50

I/O Structure

OS Notes by Dr. Naveen Choudhary

  • After I/O starts, control returns to user program only upon I/O completion. 🡪 Synchronous I/O
    • Wait instruction idles the CPU until the next interrupt
    • Wait loop (contention for memory access).🡪 infinite loop
    • Such infinite loop might also need to pool any i/o device

that do not support interrupt structure

    • POOLING :: check for a flag (in i/o device controller) to

become true or false

    • 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. 🡪 Asynchronous I/O

    • When i/o completes, the I/O device controller interrupts the

CPU to inform the CPU that it has finished it’s operation

29 of 50

Two I/O Methods

Synchronous

Asynchronous

OS Notes by Dr. Naveen Choudhary

30 of 50

Device-Status Table�The O.S also need to be able to keep track of many i/o requests at the same time. For this purpose the O.S uses a table containing an entry for each i/o device. Such table entry indicates the device type, address & status( not functioning, idle, busy)

First element in the queue : represents the request being processed

Other elements in the queue : represents the requests waiting in the

queue

OS Notes by Dr. Naveen Choudhary

31 of 50

Contd…

OS Notes by Dr. Naveen Choudhary

  • When i/o needs CPU attention (because it wants to start new operation or it has completed an operation), it interrupts
  • The O.S in response to the interrupt, first determines which i/o device raised the interrupt and then indexes into the i/o device table accordingly
  • O.s now modifies the device table entry and status accordingly (if i/o completed – also inform the waiting process accordingly )

32 of 50

Direct Memory Access Structure

OS Notes by Dr. Naveen Choudhary

  • Used for high-speed I/O devices able to transmit

information at close to memory speeds.

  • Device 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.

33 of 50

Storage Structure

OS Notes by Dr. Naveen Choudhary

  • Main memory – only large storage media that the CPU

can access directly.

  • Secondary storage – extension of main memory that

provides large nonvolatile storage capacity.

  • Magnetic disks – rigid metal or glass platters covered with

magnetic recording material

    • Disk surface is logically divided into tracks, which are

subdivided into sectors.

    • The disk controller determines the logical interaction

between the device and the computer.

34 of 50

Moving-Head Disk Mechanism

OS Notes by Dr. Naveen Choudhary

35 of 50

Magentic Tape

OS Notes by Dr. Naveen Choudhary

  • Slow
  • Good for sequential access and not good for random

access

  • Generally used as Backup media

36 of 50

Storage Hierarchy

OS Notes by Dr. Naveen Choudhary

  • Storage systems organized in hierarchy.
    • Speed
    • Cost
    • Volatility
  • Caching – copying information into faster storage system; main memory can be viewed as a last cache for secondary storage.
  • Main memory 🡪 generally dynamic RAM, cache 🡪 static

RAM

  • The program must be in main memory to be executed because main memory is the only large storage area (in addition to registers and cache) that the processor can access directly

37 of 50

Storage-Device Hierarchy

As we go down the level : access time increases,

cost per bit decreases, block size increases

Magnetic disk and below : non volatile Electronic disk :nothing but large DRAM ARRAY

OS Notes by Dr. Naveen Choudhary

38 of 50

Caching

OS Notes by Dr. Naveen Choudhary

  • Use of high-speed memory to hold recently-accessed

data.

  • Requires a cache management policy.
  • Caching introduces another level in storage hierarchy. This requires data that is simultaneously stored in more than one level to be consistent.
  • CACHE COHERENCE & CONSISTENCY

🡪 uniprocessors systems : not a big problem

🡪 multiprocessor systems : big problem

🡪 cache coherence is generally a h/w issue and is

handled below the O. S. level

39 of 50

Migration of A From Disk to Register

OS Notes by Dr. Naveen Choudhary

40 of 50

Hardware Protection

OS Notes by Dr. Naveen Choudhary

  • Dual-Mode Operation
  • I/O Protection
  • Memory Protection
  • CPU Protection

41 of 50

Dual-Mode Operation

OS Notes by Dr. Naveen Choudhary

  • Sharing system resources requires operating system to ensure that an incorrect program cannot cause other programs to execute incorrectly. (basically provides us with the means for protecting the O. S from errant users, and errant users from one another
  • Provide hardware support to differentiate between at least two

modes of operations.

    • User mode – execution done on behalf of a user.
    • Monitor mode (also kernel mode or system mode) – execution done on behalf of operating system.

🡪 Certain instruction can only be run in monitor mode

🡪 At system boot time, the h/w starts in monitor mode. The

o.s is then loaded and starts user processes in user mode

42 of 50

Dual-Mode Operation (Cont.)

  • Mode bit added to computer hardware to indicate the

current mode: monitor (0) or user (1).

  • When an interrupt or fault occurs hardware switches to

monitor mode.

Interrupt/fault/trap

monitor

user

set user mode

Privileged instructions can be issued only in monitor mode.

OS Notes by Dr. Naveen Choudhary

43 of 50

I/O Protection

OS Notes by Dr. Naveen Choudhary

  • A user program may disrupt the normal operation of the system by issuing illegal I/O instruction, by accessing memory location within the O.S itself or by refusing to relinquish the CPU
  • To prevent users from doing illegal I/O, All I/O instructions

are privileged instructions.

  • Must ensure that a user program could never gain control of the computer in monitor mode (I.e., a user program that, as part of its execution, stores a new address in the interrupt vector).

44 of 50

Use of A System Call to Perform I/O

OS Notes by Dr. Naveen Choudhary

45 of 50

Memory Protection

  • Must provide memory protection at least for the interrupt vector and the interrupt service routines. (so that an errant user does not get the power to work in protected mode)

Interrupt vector

Service routine

address 1

SRA 2

SRA 3

SRA 4

Table (in Mem)

Memo

ry

Service

Routine

🡪User Program -🡪trap to SAR4 🡪 Take address from IVT & execute the service routine (this is required to be done in monitor mode)

🡪If user modifies SAR4 address and gives there the address of his program then he can run his program in monitor mode

OS Notes by Dr. Naveen Choudhary

46 of 50

Contd ..

OS Notes by Dr. Naveen Choudhary

  • In order to have memory protection, add two registers that determine the range of legal addresses a program may access: (to protect errant users from each other)
    • Base register – holds the smallest legal physical memory

address.

    • Limit register – contains the size of the range
  • Memory outside the defined range is protected.

47 of 50

Use of A Base and Limit Register

OS Notes by Dr. Naveen Choudhary

48 of 50

Hardware Address Protection

300040

OS Notes by Dr. Naveen Choudhary

300040 +120900 = 420940

49 of 50

Hardware Protection

OS Notes by Dr. Naveen Choudhary

  • When executing in monitor mode, the operating system has unrestricted access to both monitor and user’s memory.
  • The load instructions for the base and limit registers are

privileged instructions.

50 of 50

CPU Protection

  • O.S should ensure that a process is not stuck up in an

infinite loop and so will held the CPU for ever.

  • Soln.
  • Timer – interrupts computer after specified period to

ensure operating system maintains control.

    • Timer is decremented every clock tick.
    • When timer reaches the value 0, an interrupt occurs.
  • Timer commonly used to implement time sharing.
  • Time also used to compute the current time.
  • Load-timer is a privileged instruction.

OS Notes by Dr. Naveen Choudhary