os tutorial

Upload: khan-arshid-iqbal

Post on 03-Jun-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 OS Tutorial

    1/21

    http://www.tuto rialspoint.co m/o perating _syste m/o s_quick_g uide.htm Copyright tutorialspoint.com

    OPERATING SYSTEM QUICK GUIDE

    An operating System (OS) is an intermediary between use rs and computer hardware. It provides use rs anenvironment in which a user can exe cute prog rams conveniently and efficiently.

    In technical terms, It is a software which manag es hardware . An operating System controls the allocation of

    res ource s and services such as memory, proce ssors, devices and information.

    Definition

    An operating system is a prog ram that acts as an interface between the use r and the computer hardware andcontrols the execution of all kinds of prog rams.

    Following are some of important functions of an operating System.

    Memory Manage ment

    Processor Management

    Device Manag ement

    File Manag ement

    Security

    Control over system performance

    Job accounting

    Error detecting aids

    Coordination betwee n other software and users

    TYPES OF OPERATING SYSTEM

    Operating systems are there from the ve ry first computer g eneration. Operating systems keep evolving overthe period of time. Following are few of the important types of ope rating system which are most commonly use d.

    http://www.tutorialspoint.com/operating_system/os_quick_guide.htmhttp://www.tutorialspoint.com/operating_system/os_quick_guide.htm
  • 8/12/2019 OS Tutorial

    2/21

    Batch operating system

    The users of batch operating system do not interact with the computer directly. Each user prepares his job on anoff-line device like punch cards and submits it to the computer operator. T o speed up proce ss ing , jobs withsimilar needs are batched tog ether and run as a g roup. Thus, the prog rammers left their prog rams with theoperator. T he operator then sorts prog rams into batches with similar re quirements.

    The problems with Batch Systems are following .

    Lack of interaction betwee n the user and job.

    CPU is often idle, because the speeds of the mechanical I/O device s is s lower than CPU.

    Difficult to provide the desired priority.

    Time-sharing operating systems

    Time sharing is a technique which enables many pe ople, located at various terminals, to use a particularcomputer system at the same time. T ime-sharing or multitasking is a log ical extension of multiprog ramming .Proce ssor's time which is s hared among multiple use rs simultaneously is termed as time-s haring . The maindifference between Multiprog rammed Batch Systems and Time-Sharing Systems is that in cas e of

    Multiprog rammed batch systems, obj ective is to maximize processor use , whereas in Time-Sharing Systemsobjective is to minimize response time.

    Multiple jobs are executed by the CPU by switching between them, but the switches occur so frequently. Thus,the use r can rece ives an immediate response. For e xample, in a transaction process ing , proce ssor exe cuteeach user prog ram in a short burst or quantum of computation. T hat is if n users are present, each user can g ettime quantum. When the user submits the command, the response time is in few s econds at most.

    Distributed operating System

    Distributed systems use multiple central processors to serve multiple real time application and multiple users.Data processing jobs are distributed among the proce ssors according ly to which one can perform each job

    most efficiently.The proce ssors communicate with one another throug h various communication lines (such as hig h-s peed busesor telephone lines). These are re ferred as loose ly coupled systems or distributed systems. Proce ss ors in adistributed system may vary in size and function. These processors are referred as sites, nodes, computers andso on.

    Network operating System

    Network Ope rating System runs on a server and and provides server the capability to manag e data, users,g roups, security, applications, and other networking functions. The primary purpos e of the network operatingsystem is to allow shared file and printer access among multiple computers in a network, typically a local areanetwork (LAN), a private network or to other networks. Examples of network ope rating systems are Microsoft

    Windows Se rver 2003, Microsoft Windows Se rver 2008, UNIX, Linux, Mac OS X, Novell NetWare, and BSD.

    Real Time operating System

    Real time system is defines as a data processing system in which the time interval required to proce ss andrespond to inputs is so small that it controls the environment. Real time proce ssing is always on line whereas online system need not be real time. The time taken by the system to respond to an input and display of requiredupdated information is termed as response time. So in this method response time is very less as compared to theonline processing .

    Real-time systems are used when there are rig id time requirements on the operation of a processor or the flowof data and real-time systems can be used as a control device in a dedicated application. Real-time operating

    system has well-defined, fixed time constraints otherwise system will fail.For example Scientific experiments,medical imag ing systems, industrial control systems, weapon systems, robots, and home-applicance controllers,

    Air traffic control system etc.

    OPERATING SYSTEM - SERVICES

  • 8/12/2019 OS Tutorial

    3/21

  • 8/12/2019 OS Tutorial

    4/21

    Multiprogramming

    When two or more prog rams are residing in memory at the same time, then sharing the proce ssor is re ferre d tothe multiprog ramming . Multiprog ramming assumes a s ing le shared proce ssor. Multiprog ramming incre asesCPU utilization by org anizing jobs so that the CPU always has one to e xecute.

    Following fig ure shows the memory layout for a multiprog ramming system.

    Interactivity

    Interactivity refers that a User is capable to interact with computer system. Operating system doe s the followingactivities related to interactivity.

    OS provides user an interface to interact with system.

    OS manag ers input devices to take inputs from the user. For e xample, keyboard.

    OS manag es output devices to show outputs to the user. For example, Monitor.

    OS Re sponse time needs to be short since the use r submits and waits for the result.

  • 8/12/2019 OS Tutorial

    5/21

  • 8/12/2019 OS Tutorial

    6/21

  • 8/12/2019 OS Tutorial

    7/21

    OPERATING SYSTEM - PROCESS SCHEDULING

    DefinitionThe process scheduling is the activity of the process manag er that handles the removal of the running processfrom the CPU and the selection of another proce ss on the basis of a particular strateg y.

    Proce ss scheduling is an esse ntial part of a Multiprog ramming operating system. Such operating systems allowmore than one process to be loaded into the executable memory at a time and loaded proce ss shares the CPUusing time multiplexing .

    Scheduling Queues

    Scheduling queues refers to queues of processes or device s. When the process enters into the sys tem, thenthis proce ss is put into a job queue. This queue consists of all process es in the system. The operating systemalso maintains other queues such as de vice queue. Device queue is a queue for which multiple process es are

    waiting for a particular I/O device. Each device has its own device queue.

    This fig ure shows the queuing diag ram of process scheduling .

    Queue is represented by rectang ular box.

    The circles repre se nt the re sources that se rve the queues.

    The arrows indicate the process flow in the system.

  • 8/12/2019 OS Tutorial

    8/21

    Queues are of two types

    Ready queue

    Device queue

    A newly arrived proce ss is put in the re ady queue. Processes waits in ready queue for allocating the CPU. Oncethe CPU is assig ned to a process, then that process will execute. While executing the process, any one of thefollowing events can occur.

    The process could issue an I/O re quest and then it would be place d in an I/O queue.

    The process could create new sub proce ss and will wait for its termination.

    The process could be removed forcibly from the CPU, as a result of interrupt and put back in the readyqueue.

    Two State Process Model

    Two state process model refers to running and non-running states which are described below.

    S.N. State & Description

    1 RunningWhen new process is cre ated by Operating System that process enters into the system as in therunning state.

    2 Not RunningProcesses that are not running are kept in queue, waiting for their turn to e xecute. Each entry in thequeue is a pointer to a particular proce ss. Queue is implemented by using linked list. Use of

    dispatcher is as follows. When a proce ss is interrupted, that proce ss is transferre d in the waitingqueue. If the proce ss has completed or aborted, the proce ss is discarded. In either case, thedispatcher then se lects a proce ss from the queue to exe cute.

    Schedulers

  • 8/12/2019 OS Tutorial

    9/21

    Schedulers are spe cial system softwares which handles process scheduling in various ways.T heir main task is tose lect the jobs to be submitted into the system and to decide which proce ss to run. Schedulers are of three types

    Long Term Scheduler

    Short Term Scheduler

    Medium Term Scheduler

    OS - SCHEDULING ALGORITHMS

    We'll discuss four major scheduling algorithms here which are following

    First Come First Serve (FCFS) Scheduling

    Shortes t-Job-First (SJF) Scheduling

    Priority Scheduling

    Round Robin(RR) Scheduling

    Multilevel Queue Scheduling

    OPERATING SYSTEM - MULTI-THREADING

    What is Thread?

    A thread is a flow of execution through the proce ss code, with its own prog ram counter, system reg isters andstack. A thread is also called a lig ht weig ht proce ss. T hreads provide a way to improve application performancethrough parallelism. T hreads represent a software approach to improving performance of operating system byreducing the overhead thread is equivalent to a classical proce ss.

    Each thread belongs to exactly one process and no thread can exist outside a process. Each thread representsa separate flow of control.Threads have been successfully use d in implementing network servers and webserver. They also provide a suitable foundation for parallel execution of applications on shared memorymultiprocessors. Folowing fig ure shows the working of the sing le and multithreaded processes.

    Difference between Process and Thread

  • 8/12/2019 OS Tutorial

    10/21

    S.N. Process Thread

    1 Process is heavy weig ht or resource intensive. Thread is lig ht weig ht taking lesser resourcesthan a process.

    1 Process switching needs interaction withoperating system.

    Thread switching doe s not need to interact withoperating s ystem.

    1 In multiple processing environments eachproce ss exe cutes the same code but has itsown memory and file resources.

    All threads can share same set of open files, childprocesses.

    1 If one process is blocked then no otherprocess can execute until the first process isunblocked.

    While one thread is blocked and waiting , se condthread in the same task can run.

    1 Multiple processes without using threads usemore res ources .

    Multiple threaded proce ss es use fewerresources.

    1 In multiple processes each process operatesindependently of the others.

    One thread can read, write or chang e anotherthread's data.

    Advantages of Thread

    Thread minimize context switching time.

    Use of threads provides concurrency within a process.

    Efficient communication.

    Economy- It is more economical to create and context switch threads.

    Utilization of multiprocessor architectures to a g reater scale and e fficiency.

    Types of Thread

    Threads are implemented in following two ways

    User Level Threads-- User manag ed threads

    Kernel Level Threads-- Operating System manag ed threads acting on kernel, an operating systemcore.

    OS - MEMORY MANAGEMENTMemory manag ement is the functionality of an operating system which handles or manag es primary memory.Memory manag ement keeps track of each and every memory location either it is allocated to some process or itis free. It checks how much memory is to be allocated to processes. It decides which process will g et memory at

    what time. It tracks whenever some memory g ets freed or unallocated and corre sponding ly it updates the s tatus.

    Memory manag ement provides protection by using two reg isters, a base reg ister and a limit reg ister. T he basereg ister holds the smallest leg al physical memory addre ss and the limit reg ister specifies the size of the rang e.For example, if the base reg ister holds 300000 and the limit reg ister is 1209000, then the prog ram can leg allyacce ss all addresse s from 300000 throug h 411999.

  • 8/12/2019 OS Tutorial

    11/21

    Instructions and data to memory addresses can be done in following ways

    Compile time-- When it is known at compile time where the proce ss will reside, compile time binding isuse d to g enerate the absolute code.

    Load time -- When it is not known at compile time where the proce ss will reside in memory, then thecompiler generates re -locatable code.

    Execution time -- If the process can be moved during its execution from one memory s eg ment toanother, then binding must be delayed to be done at run time

    Dynamic Loading

    In dynamic loading , a routine of a prog ram is not loaded until it is called by the prog ram. All routines are kept ondisk in a re-locatable load format. The main prog ram is loaded into memory and is executed. Other routinesmethods or modules are loaded on request. Dynamic loading makes better memory s pace utilization and unusedroutines are never loaded.

    Dynamic Linking

    Linking is the proce ss of collecting and combining various modules of code and data into a executable file that canbe loaded into memory and exe cuted. Operating system can link system level libraries to a prog ram. When itcombines the libraries at load time, the linking is called static linking and when this linking is done at the time ofexecution, it is called as dynamic linking .

    In static linking , libraries linked at compile time, so prog ram code size becomes big g er whereas in dynamiclinking libraries linked at exe cution time so prog ram code size remains smaller.

    Logical versus Physical Address Space

    An address g enerated by the C PU is a log ical address whereas address actually available on memory unit is aphysical address. Log ical address is also known a Virtual address.

    Virtual and physical addresse s are the same in compile-time and load-time addre ss-binding schemes. Virtual andphysical addresse s differ in execution-time address-binding scheme.

    The set of all log ical addresse s g enerated by a prog ram is re ferred to as a logical address space. The se t of allphysical addresse s corresponding to these log ical addresse s is referred to as a physical address space.

  • 8/12/2019 OS Tutorial

    12/21

    The run-time mapping from virtual to physical address is done by the memory manag ement unit (MMU) which isa hardware device . MMU use s following mechanism to convert virtual address to physical addres s.

    The value in the base reg ister is added to eve ry address g enerated by a use r proce ss which is treated asoffse t at the time it is sent to memory. For e xample, if the base reg ister value is 10000, then an attempt bythe user to use address location 100 will be dynamically reallocated to location 10100.

    The use r prog ram deals with virtual addresse s; it never se es the real physical addresse s.

    SwappingSwapping is a mechanism in which a proce ss can be swapped temporarily out of main memory to a backing store, and then broug ht back into memory for continued execution.

    Backing store is a usually a hard disk drive or any other secondary storage which fast in access and larg e enoughto accommodate copies of all memory imag es for all use rs. It must be capable of providing direct access tothes e memory images.

    Major time consuming part of swapping is transfer time. T otal transfer time is directly proportional to the amountof memory swapped. Let us assume that the user process is of size 100KB and the backing store is a s tandardhard disk with transfer rate of 1 MB per second. T he actual transfer of the 100K process to or from memory willtake

    100KB / 1000KB per second

    = 1/10 second

    = 100 milliseconds

    Memory Allocation

    Main memory usually has two partitions

    Low Memory-- Operating system resides in this memory.

    High Memory-- User processe s then held in hig h memory.

    Ope rating system uses the following memory allocation mechanism.

  • 8/12/2019 OS Tutorial

    13/21

    S.N. Memory Allocation

    Description

    1 Single-partitionallocation

    In this type of allocation, re location-reg ister scheme is use d to protect userprocesses from each other, and from chang ing operating -system code anddata. Re location reg ister contains value of smallest physical address whereaslimit reg ister contains range of logical addresse s. Each logical address must

    be less than the limit reg ister.

    2 Multiple-partitionallocation

    In this type of allocation, main memory is divided into a number of fixed-sizedpartitions where each partition should contain only one proce ss. When apartition is free, a process is selected from the input queue and is loaded intothe free partition. When the process terminates, the partition becomesavailable for another process.

    Fragmentation

    As process es are loaded and removed from memory, the free memory space is broken into little pieces. Ithappens after sometimes that proce ss es can not be allocated to memory blocks considering their small size andmemory blocks remains unused. T his problem is known as Frag mentation.

    Frag mentation is of two types

    S .N. Frag mentatio n Desc riptio n

    1 Externalfragmentation

    Total memory space is e nough to satisfy a request or to reside a process in it,but it is not contig uous so it can not be use d.

    2 Internalfragmentation

    Memory block assigned to process is big g er. Some portion of memory is leftunused as it can not be used by another process .

    External frag mentation can be reduced by compaction or shuffle memory contents to place all free memorytogether in one larg e block. T o make compaction feasible, relocation should be dynamic.

    Paging

    External frag mentation is avoided by using pag ing technique. Pag ing is a technique in which physical memory isbroken into blocks of the same s ize called pages (size is power of 2, betwee n 512 bytes and 8192 bytes). Whena proce ss is to be e xecuted, it's corresponding pag es are loaded into any available memory frames.

    Log ical addres s space of a proces s can be non-contig uous and a process is allocated physical memorywhenever the free memory frame is available. Ope rating system kee ps track of all free frames. Operatingsystem needs n free frames to run a prog ram of size n pages.

    Address g enerated by CPU is divided into

    Page number (p)-- pag e number is used as an index into a page table which contains base address ofeach pag e in physical memory.

    Page offset (d)-- page offset is combined with base address to define the physical memory addre ss.

  • 8/12/2019 OS Tutorial

    14/21

    Following fig ure show the pag ing table architecture.

    Segmentation

    Seg mentation is a technique to break memory into log ical piece s where each piece represents a g roup ofrelated information. For example ,data se g ments or code s eg ment for each process , data seg ment forope rating system and so on. Se g mentation can be implemented using or without using pag ing .

    Unlike pag ing , seg ment are having varying sizes and thus eliminates internal frag mentation. External

    frag mentation still exists but to les ser extent.

  • 8/12/2019 OS Tutorial

    15/21

    Address g enerated by CPU is divided into

    Segment number (s)-- seg ment number is use d as an index into a seg ment table which contains baseaddre ss of each seg ment in physical memory and a limit of seg ment.

    Seg ment offset (o) -- seg ment offset is first checked ag ainst limit and then is combined with baseaddress to define the physical memory addre ss.

    OPERATING SYSTEM - VIRTUAL MEMORY

    Virtual memory is a technique that allows the e xecution of processes which are not completely available inmemory. T he main visible advantag e of this scheme is that prog rams can be larger than physical memory. Virtual

    memory is the separation of user log ical memory from physical memory.

    This separation allows an extremely larg e virtual memory to be provided for prog rammers when only a smallerphysical memory is available. Following are the situations, when entire prog ram is not required to be loaded fullyin main memory.

  • 8/12/2019 OS Tutorial

    16/21

    User written error handling routines are used only when an error occured in the data or computation.

    Ce rtain options and features of a prog ram may be used rare ly.

    Many tables are assig ned a fixed amount of address space even though only a small amount of the table isactually used.

    The ability to e xecute a prog ram that is only partially in memory would counter many benefits.

    Less number of I/O would be needed to load or swap each user prog ram into memory.

    A prog ram would no longe r be constrained by the amount of physical memory that is available.

    Each user prog ram could take less physical memory, more prog rams could be run the same time, with acorre sponding increase in CPU utilization and throughput.

    Virtual memory is commonly implemented by demand paging . It can also be implemented in a seg mentationsystem. Demand seg mentation can also be used to provide virtual memory.

    OPERATING SYSTEM - I/O HARDWARE

    Overview

    Computers operate on many kinds of device s. General types include storage devices(disks, tapes),transmission devices(network cards, modems), and human-interface devices(scree n, keyboard, mouse).Other device s are more specialize d. A device communicates with a computer system by sending signals over acable or even through the air.

    The device communicates with the machine via a connection point termed aport(for example, a serial port). Ifone or more device s use a common set of wires, the connection is called a bus.In other terms, a bus is a set of

    wires and a rig idly defined protocol that specifies a set of messag es that can be sent on the wires.

    Daisy chain

    When device A has a cable that plug s into device B, and device B has a cable that plug s into device C, and deviceC plug s into a port on the computer, this arrang ement is called a daisy chain. It usually ope rates as a bus.

    Controller

  • 8/12/2019 OS Tutorial

    17/21

    A controller is a collection of electronics that can operate a port, a bus, or a device. A se rial-port controller is anexample of a simple de vice controller. T his is a sing le chip in the computer that controls the sig nals on the wiresof a serial port.

    The SCSI bus controller is often implemented as a separate circuit board (a host adapter) that plugs into thecomputer. It contains a processor, microcode, and some private memory to e nable it to proce ss the SCSIprotocol mess ag es. Some device s have their own built-in controllers.

    I/O portAn I/O port typically consists of four reg isters, called the status , control, data-in, and data-outreg isters.

    S.N. Register & Description

    1 Status Reg isterThe status reg ister contains bits that can be read by the host. These bits indicate states such as

    whether the current command has completed, whether a byte is available to be read from the data-inreg ister, and whether there has be en a device error.

    2 Control reg isterThe control reg ister can be written by the host to s tart a command or to chang e the mode of a device .For instance , a ce rtain bit in the control reg ister of a serial port chooses between full-duplex and half-duplex communication, another e nables parity checking , a third bit se ts the word length to 7 or 8 bits,and other bits s elect one of the spe eds s upported by the se rial port.

    3 Data-in registerThe data-in reg ister is re ad by the host to g et input.

    4 Data-out reg isterThe data out reg ister is written by the host to send output.

    Polling

    Polling is a process by which a host waits for controller response.It is a looping process, reading the statusreg ister ove r and over until the busy bit of status re g ister becomes clear. The controller uses/sets the busy bit

    when it is busy working on a command, and clears the busy bit when it is re ady to accept the next command. Thehost signals its wish via the command-ready bit in the command reg ister. The host sets the command-ready bit

    when a command is available for the controller to execute.

    In the following example, the host writes output through a port, coordinating with the controller by handshaking

    The host repe atedly reads the busy bit until that bit becomes clear.

    The host sets the write bit in the command reg ister and writes a byte into the data-out reg ister.

    The host sets the command-re ady bit.

    When the controller notice s that the command-re ady bit is set, it sets the busy bit.

    The controller re ads the command reg ister and sees the write command.

    It reads the data-out reg ister to get the byte, and does the I/O to the device .

    The controller clears the command-ready bit, clears the error bit in the status reg ister to indicate that thedevice I/O succeeded, and clears the busy bit to indicate that it is finished.

    I/O devices

    I/O De vices can be categ orize d into following categ ory.

  • 8/12/2019 OS Tutorial

    18/21

    S.N. Category & Description

    1 Human readableHuman Readable devices are suitable for communicating with the computer user. Examples areprinters, video display terminals, keyboard etc.

    2 Machine readableMachine Readable devices are suitable for communicating with electronic e quipment. Examples aredisk and tape drives, sensors, controllers and actuators.

    2 CommunicationCommunication devices are suitable for communicating with remote devices. Examples are digital linedrivers and modems.

    Following are the differe nces between I/O Device s

    S.N. Criteria & Description

    1 Data rate

    There may be differences of several orders of magnitude between the data transfer rates.

    2 ApplicationDiffere nt devices have different use in the system.

    3 Complexity of ControlA disk is much more complex whereas printer requires s imple control interface .

    4 Unit of transferData may be transferred as a stream of bytes or characters or in larger blocks.

    5 Data representation

    Differe nt data encoding schemes are use d for differe nt device s.

    6 Error ConditionsThe nature of errors differs widely from one device to another.

    Direct Memory Acces s (DMA)

    Many computers avoid burdening the main CPU with prog rammed I/O by offloading some of this work to aspe cial purpose process or. This type of proce ssor is called, a Direct Memory Acces s(DMA) controller. Aspecial control unit is used to transfer block of data directly between an external device and the main memory,

    without intervention by the proce ssor. This approach is called Direct Memory Access(DMA).

    DMA can be used with either polling or interrupt software. DMA is particularly use ful on devices like disks,where many bytes of information can be transferre d in sing le I/O operations. When use d with an interrupt, theCPU is notified only after the entire block of data has been transferre d. For e ach byte or word transferre d, itmust provide the memory addre ss and all the bus s ig nals controlling the data transfer. Interaction with a devicecontroller is manag ed through a device driver.

    Handshaking is a process between the DMA controller and the device controller. It is performed via wires usingterms DMA request and DMA acknowledge.

  • 8/12/2019 OS Tutorial

    19/21

    Step Description

    1 Device driver is instructed to transfer disk data to a buffer address X.

    2 Device driver then instruct disk controller to transfer data to buffer.

    3 Disk controller starts DMA transfer.

    4 Disk controller sends each byte to DMA controller.

    5 DMA controller transfers bytes to buffer, increases the memory address, decreases the counter Cuntil C becomes zero.

    6 When C becomes ze ro, DMA interrupts CPU to sig nal transfer completion.

    Device Controllers

    A computer system contains a many types of I/O device s and their respective controllers

    network card

    g raphics adapter

    disk controller

    DVD-ROM controller

    serial port

    USB

    sound card

  • 8/12/2019 OS Tutorial

    20/21

    OPERATING SYSTEM - I/O SOFTWARES

    Interrupts

    The CPU hardware use s an interrupt request line wire which helps CPU to sense after executing everyinstruction. When the CPU checks that a controller has put a signal on the interrupt request line, the CPU saves astate, such as the current value of the instruction pointer, and jumps to the interrupt handler routine at a fixedaddress. T he interrupt handler part determines the cause of the interrupt, performs the nece ssary proce ssingand executes a interrupt instruction to return the CPU to its execution state.

    The basic mechanism of interrurpt enables the CPU to respond to an asynchronous event, such as when a devicecontroller become ready for service. Most CPUs have two interrupt request lines.

    non-maskable interrupt- Such kind of interrupts are reserved for events like unrecoverable memoryerrors.

    maskable interrupt- Such interrupts can be switched off by the CPU be fore the execution of criticalinstructions that must not be interrupted.

    The interrupt mechanism acce pts an address - a number that se lects a specific interrupt handlingroutine/function from a small se t.In most architectures, this addre ss is an offse t store d in a table called the

    interrupt vector table. T his vector contains the memory address es of specialize d interrupt handlers.

    Application I/O Interface

    Application I/O Interface represe nts the s tructuring techniques and interfaces for the operating system toenable I/O device s to be treated in a standard, uniform way. T he actual difference s lies kernel level modulescalled device drivers which are custom tailore d to corresponding device s but show one of the standardinterfaces to applications. The purpose of the device -driver layer is to hide the difference s among devicecontrollers from the I/O subsystem of the kernel, such as the I/O system calls. Following are the characteristicsof I/O interfaces with respe cted to devices.

    Character-stream / block - A character-s tream device transfers bytes in one by one fashion,

    whereas a block device transfers a complete unit of bytes.Sequential / random-access- A sequential device transfers data in a fixed order determined by thedevice , random-access device can be instructed to seek position to any of the available data storag elocations.

    Synchronous / asynchronous- A synchronous device performs data transfers with knownresponse time where as an asynchronous device shows irreg ular or unpredictable response time.

    Sharable / dedicated- A sharable device can be used concurrently by se veral processes or threadsbut a dedicated device cannot be used.

    Spee d of operation- Device spe eds may rang e from a few bytes per se cond to a few g ig abytes per

    second.

    Read-write, read only, or write only- Some devices perform both input and output, but otherssupport only one data direction that is read only.

    Clocks

    Clocks are also called timers. The clock software takes the form of a device driver though a clock is neither ablocking device nor a character base d device. The clock software is the clock driver. The e xact function of theclock driver may vary depending on operating system. Generally, the functions of the clock driver include thefollowing .

    S.N. Task Description

    1 Maintaining the time of the day The clock driver implements the time of day or thereal time clock function.It requires incrementing acounter at each clock tick.

  • 8/12/2019 OS Tutorial

    21/21

    2 Preventing processes from running too long As a process is started, the scheduler initializesthe quantum counter in clock ticks for the proce ss.The clock driver decrements the quantum counter

    by 1, at every clock interrupt. When the counterg ets to zero , clock driver calls the scheduler tose t up another process. Thus c lock driver helps inpreventing processes from running long er thantime slice allowed.

    3 Accounting for CPU usag e Another function performed by clock driver isdoing CPU accounting . CPU accounting impliestelling how long the process has run.

    4 Providing watchdog timers for parts of thesystem itself

    Watchdog timers are the timers set by certainparts of the system. For example, to use a floppydisk, the system must turn on the motor and then

    wait about 500msec for it to comes up to speed.

    Kernel I/O Subsystem

    Kernel I/O Subsystem is responsible to provide many service s related to I/O. Following are some of these rvices provided.

    Scheduling - Kernel schedules a set of I/O requests to determine a g ood order in which to executethem. When an application issues a blocking I/O s ystem call, the request is placed on the queue for thatdevice. The Kernel I/O scheduler rearrang es the order of the queue to improve the overall systemefficiency and the averag e response time experience d by the applications.

    Buffering - Kernel I/O Subsystem maintains a memory are a known as buffer that stores data while theyare transferre d be tween two de vice s or between a device with an application operation. Buffering is doneto cope with a speed mismatch between the producer and consumer of a data stream or to adapt betweendevice s that have different data transfer s ize s.

    Caching - Kernel maintains cache memory which is reg ion of fast memory that holds copies of data.Acce ss to the cached copy is more e fficient than access to the orig inal.

    Spooling and Device ReservationA spool is a buffer that holds output for a device, such as aprinter, that cannot accept interleave d data streams. The spooling system copies the queued spool files tothe printer one at a time. In some operating systems, spooling is manag ed by a system daemon process .In other operating systems, it is handled by an in kernel thread.

    Error Handling An ope rating system that uses protected memory can guard against many kinds ofhardware and application errors.

    Device driverDevice driver is a prog ram or routine developed for an I/O de vice . A device driver implements I/O operationsor be haviours on a specific c lass of device s. For e xample a system supports one or a number of multiple brandsof terminals, all slig htly different terminals may have a s ing le terminal driver. In the layered structure of I/Osystem, device driver lies between interrupt handler and device independent I/O software. The job of a devicedriver are following .

    To accept request from the device independent software above it.

    To see to it that the request is executed.