os intro [compatibility mode]

Upload: manoj-kathuria

Post on 02-Mar-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/26/2019 OS Intro [Compatibility Mode]

    1/53

    OPERATING SYSTEMS

    Prachi PandeyC-DAC, Bangalore

  • 7/26/2019 OS Intro [Compatibility Mode]

    2/53

  • 7/26/2019 OS Intro [Compatibility Mode]

    3/53

    Managing all these varied components requiresa layer of software the Operating System (OS).

  • 7/26/2019 OS Intro [Compatibility Mode]

    4/53

    An Operating System is a program that acts as aninterface between a user of a computer and the

    computer hardware.

  • 7/26/2019 OS Intro [Compatibility Mode]

    5/53

    Primary Goal Convenience

    Secondary Goal - Efficiency

    Or is it the other way round?

  • 7/26/2019 OS Intro [Compatibility Mode]

    6/53

    Source CodeCompilerObject CodeHardware

    How do you get object code onto the hardware?

    How do you print out the answer?

    Once upon a time, had to Toggle in program inbinary and read out answer from LEDs!

    Altair 8080

  • 7/26/2019 OS Intro [Compatibility Mode]

    7/53

    Control/execute user/application programs.

    Make the computer system convenient to use.

    Ease the solving of user problems.

    Use the computer hardware in an efficientmanner.

    Provide isolation, security and protectionamong user programs.

  • 7/26/2019 OS Intro [Compatibility Mode]

    8/53

    Every piece of computer hardware different

    Different CPU

    o Pentium, PowerPC, ColdFire, ARM, MIPS

    Different amounts of memory, disk,

    Different types of devices

    o Mice, Keyboards, Sensors, Cameras,Fingerprint readers

    Different networking environment

    o Cable, DSL, Wireless, Firewalls,

  • 7/26/2019 OS Intro [Compatibility Mode]

    9/53

    Questions:

    Does the programmer need to write a singleprogram that performs many independentactivities?

    Does every program have to be altered forevery piece of hardware?

    Does a faulty program crash everything?

    Does every program have access to allhardware?

  • 7/26/2019 OS Intro [Compatibility Mode]

    10/53

  • 7/26/2019 OS Intro [Compatibility Mode]

    11/53

    Batch Operating Systems

    Time Sharing Operating Systems

    Multiprocessor Operating Systems

    Network Operating Systems

    Real Time Operating Systems

  • 7/26/2019 OS Intro [Compatibility Mode]

    12/53

    Users did not interact with computer directly. Each user submitted his/her jobs to the operator

    who in turn fed the programs to the computer.

    User had to come back later to collect the output.

  • 7/26/2019 OS Intro [Compatibility Mode]

    13/53

    Early batch system

    1. bring cards to 1401

    2. read cards to tape

    3. put tape on 7094 which does computing

    4. put tape on 1401 which prints output

  • 7/26/2019 OS Intro [Compatibility Mode]

    14/53

    Disadvantages

    Lack of interaction between the user and job.

    CPU is often idle, because the speeds of the

    mechanical I/O devices is slower than CPU.

    Difficult to provide the desired priority.

  • 7/26/2019 OS Intro [Compatibility Mode]

    15/53

    To understand time-sharing OS we need to understand aconcept called Multiprogramming.

    Multiprogramming means sharing of resourcesbetween more than one processes.

    CPU time is not wasted, because, while one processmoves on some I/O work, the OS picks another processto execute till the current one passes to I/O operation.

    Goal of multiprogramming is to efficiently utilize all

    of the computing resources.

  • 7/26/2019 OS Intro [Compatibility Mode]

    16/53

    Time sharing is a technique which enables many people,located at various terminals, to use a particular computersystem at the same time.

    Terminals areconnected to the main

    computer and used forinput and output. Noprocessing is made.They do not haveCPUs.

    Main computer; having aCPU executing processes byutilization of the OS, (e.g.UNIX).

  • 7/26/2019 OS Intro [Compatibility Mode]

    17/53

    Time-sharing or multitasking is a logical extension ofmultiprogramming.

    In Time Sharing OS

    OS switches between users programs very quickly,generally in round-robin fashion.

    Switching between users is very fast.

    Goal is to give the illusion that each user has his/herown machine.

    Response time is a priority.

  • 7/26/2019 OS Intro [Compatibility Mode]

    18/53

    Has multiple processors sharing memory andperipheral devices.

    With this configuration, they have greatercomputing power and higher reliability.

    Multiprocessor systems are classified into two astightly-coupled and loosely-coupled (distributed).

    In the tightly-coupled one, each processor isassigned a specific duty but processors work in

    close association, possibly sharing the samememory.

    In the loosely coupled one, each processor has itsown memory and copy of the OS.

  • 7/26/2019 OS Intro [Compatibility Mode]

    19/53

    In network systems, each process runs in its ownmachine but the OS have access to other machines.

    In networks, users are aware of the fact that s/he isworking in a network and when information isexchanged.

    The user explicitly handles the transfer ofinformation.

  • 7/26/2019 OS Intro [Compatibility Mode]

    20/53

    A real-time operating system is an operating systemthat guarantees to process events or data within acertain short amount of time.

    A real-time operating system may be single- or multi-tasking, but when multitasking, it uses specializedscheduling algorithms so that a deterministic nature ofbehavior is achieved.

  • 7/26/2019 OS Intro [Compatibility Mode]

    21/53

  • 7/26/2019 OS Intro [Compatibility Mode]

    22/53

    Problem:How to run multiple applications in such a way thatthey are protected from one another

    Goal: Keep User Programs from Crashing each other

    Keep User Programs from Crashing OSKeep Parts of OS from crashing other parts?

    Simple Policy:Programs are not allowed to read/write memory ofother Programs or of Operating System

    Mechanisms: Address Translation Dual Mode Operation

  • 7/26/2019 OS Intro [Compatibility Mode]

    23/53

    Prog 1

    Virtual

    Address

    Space 1

    Prog 2

    Virtual

    Address

    Space 2

    Code

    Data

    Heap

    Stack

    Code

    Data

    Heap

    Stack

    Data 2

    Stack 1

    Heap 1

    OS heap &

    Stacks

    Code 1

    Stack 2

    Data 1

    Heap 2

    Code 2

    OS code

    OS dataTranslation Map 1 Translation Map 2

    Physical Address Space

  • 7/26/2019 OS Intro [Compatibility Mode]

    24/53

    Two modes:o Kernel mode (or supervisor or protected)o User mode: Normal programs executed

    Some instructions/ops prohibited in user mode:o

    Example: cannot modify page tables in user mode Attempt to modify Exception generated Transitions from user mode to kernel mode:

    o System Calls, Interrupts, Other exceptions

  • 7/26/2019 OS Intro [Compatibility Mode]

    25/53

    Process Management

    Main Memory Management

    Storage Management

    I/O System Management

    Networking

    Protection System

    Command-Interpreter System

  • 7/26/2019 OS Intro [Compatibility Mode]

    26/53

    A process is a program in execution

    Process needs resources to accomplish its task

    Process termination requires reclaim of any reusableresources

    Single-threaded process has one program counterspecifying location of next instruction to execute

    Multi-threaded process has one program counter perthread

    Typically system has many processes, some user,some operating system running concurrently on oneor more CPUs-Concurrency is achieved by multiplexing the CPUs amongthe processes / threads

  • 7/26/2019 OS Intro [Compatibility Mode]

    27/53

    The operating system is responsible for the followingactivities in connection with process management:

    Creating and deleting both user and systemprocesses

    Suspending and resuming processes

    Providing mechanisms for processsynchronization

    Providing mechanisms for processcommunication

    Providing mechanisms for deadlock handling

  • 7/26/2019 OS Intro [Compatibility Mode]

    28/53

    Memory management activities

    o Keeping track of which parts of memory are

    currently being used and by whom

    o Deciding which processes (or parts thereof) anddata to move into and out of memory

    o Allocating and deallocating memory space as

    needed

  • 7/26/2019 OS Intro [Compatibility Mode]

    29/53

    OS provides uniform, logical view of information storage Abstracts physical properties to logical storageunit - file Each medium is controlled by device (i.e., diskdrive, tape drive)

    -Varying properties include access speed, capacity,data-transfer rate, access method (sequential orrandom)

    OS activities include

    Creating and deleting files and directories

    Primitives to manipulate files and directories

    Mapping files onto secondary storage

  • 7/26/2019 OS Intro [Compatibility Mode]

    30/53

    One purpose of OS is to hide peculiarities ofhardware devices from the user.

    I/O subsystem responsible for scheduling

    (Efficiency, fairness, prioritized access) buffering

    (storing data temporarily while it is beingtransferred),

    caching (storing parts of data in faster storage for

    performance),

    device-driver interface

  • 7/26/2019 OS Intro [Compatibility Mode]

    31/53

    The kernel is the central module of an operatingsystem (OS).

    It is the part of the operating system that loadsfirst, and it remains in main memory.

  • 7/26/2019 OS Intro [Compatibility Mode]

    32/53

    The Unix kernel

    Consists of everything below the system-call interfaceand above the physical hardware

  • 7/26/2019 OS Intro [Compatibility Mode]

    33/53

    Kernel components

    File ManagerMaintains information about the files that are availableon the system

    Device DriversSoftware to communicate with peripheral devices orcontrollers

    Memory ManagerThis unit is responsible for coordinating the use of themachines main memory

    Scheduler & DispatcherThese units together manage processes

  • 7/26/2019 OS Intro [Compatibility Mode]

    34/53

    Roles of a kernel

    responsible for the creation and destruction ofmemory space which allows software to run

    provides services so that programs can requestthe use of the network card, the disk or any otherpiece of hardware

    manages the file system and sets interrupts forthe CPU to enable multitasking.

    responsible for ensuring that faulty programs donot interfere with the operation of others

  • 7/26/2019 OS Intro [Compatibility Mode]

    35/53

    System memory can be divided into two distinctregions: kernel space and user space.

    Kernel space is where the kernel (i.e., the core of theoperating system) executes (i.e., runs) and provides

    its services.

    User space is that set of memory locations inwhich user processes (i.e., everything other than thekernel) run.

  • 7/26/2019 OS Intro [Compatibility Mode]

    36/53

    Also called privileged mode, also referred to assystem mode.

    Used mainly for Restriction/ Protection from

    unauthorized user application program

    When the CPU is in kernel mode, it is assumed tobe executing trusted software, and thus it canexecute any instructions and reference anymemory addresses (i.e., locations in memory).

    all other programs(user applications) areconsidered untrusted software.

  • 7/26/2019 OS Intro [Compatibility Mode]

    37/53

    Example:

    A good example of this would be device drivers.

    A device driver must tell the kernel exactly how to

    interact with a piece of hardware, so it must be run inkernel mode.

    Because of this close interaction with the kernel, the

    kernel is also a lot more vulnerable to programs

    running in this mode, so it becomes highly crucialthat drivers are properly debugged before being

    released to the public.

  • 7/26/2019 OS Intro [Compatibility Mode]

    38/53

    It is a non-privileged mode.

    It is non-privileged in that it is forbidden forprocesses in this mode to access those portions ofmemory (i.e., RAM) that have been allocated to thekernel or to other programs.

    User mode is the normal mode of operating forprograms.

    Code running in user mode must delegate to system

    APIs to access hardware or memory.

    Most of the code running on your computer willexecute in user mode.

  • 7/26/2019 OS Intro [Compatibility Mode]

    39/53

    When a user mode process wants to use a servicethat is provided by the kernel, it must switchtemporarily into kernel mode, which has root privileges,including root access permissions.

    When the kernel has satisfied the process's request, itrestores the process to user mode.

  • 7/26/2019 OS Intro [Compatibility Mode]

    40/53

    Monolithic Kernel

    Microkernels

    Hybrid Kernels

  • 7/26/2019 OS Intro [Compatibility Mode]

    41/53

    All OS services run along with the main kernelthread.

    They also reside in the same memory area

    This approach provides rich and powerfulhardware access

    Linux and FreeBSD

  • 7/26/2019 OS Intro [Compatibility Mode]

    42/53

  • 7/26/2019 OS Intro [Compatibility Mode]

    43/53

    Moves as much from the kernel into user space

    Communication takes place between user modulesusing message passing

    Benefits:

    Easier to extend a microkernel Easier to port the operating system to newarchitectures More reliable (less code is running in kernelmode) More secure

    Disadvantages: Performance overhead of user space to kernelspace communication

    AIX, BeOS, Hurd, Mach, Mac OS X, MINIX, QNX

  • 7/26/2019 OS Intro [Compatibility Mode]

    44/53

  • 7/26/2019 OS Intro [Compatibility Mode]

    45/53

    They are similar to micro kernels, except theyinclude some additional code in kernel-space toincrease performance

    This approach combines the speed and simplerdesign of a monolithic kernel with the modularity andexecution safety of a microkernel.

    MS Windows NT to 8.1, Mac OSX

  • 7/26/2019 OS Intro [Compatibility Mode]

    46/53

  • 7/26/2019 OS Intro [Compatibility Mode]

    47/53

    Example

  • 7/26/2019 OS Intro [Compatibility Mode]

    48/53

  • 7/26/2019 OS Intro [Compatibility Mode]

    49/53

    Interrupt transfers control to the interrupt service routine

    o determine action to be taken for each type of interrupt.

    o Interrupt vector contains the address of service

    routines.

    OS preserves the state of the CPU

    o stores registers and the program counter (address of

    interrupted instruction).

    Trap

    o software generated interrupt caused either by an error

    or a user request.

  • 7/26/2019 OS Intro [Compatibility Mode]

    50/53

    Types of interrupto Pollingo Vectored interrupt system

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

  • 7/26/2019 OS Intro [Compatibility Mode]

    51/53

    The only way an user space application can explicitly initiate aswitch to kernel mode during normal operation is by makinga system call such as open, read, write etc.

    Whenever a user application calls these system call APIs withappropriate parameters, a software interrupt/exception(SWI)

    is triggered.

    As a result of this SWI, the control of the code executionjumps from the user application to a predefined location inthe Interrupt Vector Table [IVT] provided by the OS.

    This IVT contains an address for the SWI exception handlerroutine, which performs all the necessary steps required toswitch the user application to kernel mode and startexecuting kernel instructions on behalf of user process.

  • 7/26/2019 OS Intro [Compatibility Mode]

    52/53

    REFERENCES

    Operating System Principles, by Galvin, Wiley

    Berkley CS 162 course: ProfJohn Kubiatowicz

    Operating System Gate lectures by RavindrababuRavula

  • 7/26/2019 OS Intro [Compatibility Mode]

    53/53