How is a device dependent program different from a device independent program?

Device independence is the characteristic of programs that work on any type of device, DASD or tape, for example. Achieving device independence is possible only for a sequential data set because input or output can be on DASD, a magnetic tape drive, a card reader or card punch, a printer, a spooled data set, a TSO/E terminal, or a dummy data set. Other data set organizations (partitioned, direct, and VSAM) are device-dependent because they require the use of DASD.

A dummy data set is a DD statement on which the first parameter is DUMMY or you coded the DDNAME= parameter but there is no DD statement by that name. You can use BSAM or QSAM with a dummy data set. A WRITE or PUT macro has no effect. A GET macro or the CHECK macro for the first READ macro causes your EODAD routine to be called.

Device independence can be useful for the following tasks:

  • Accepting data from several recording devices, such as a disk volume, magnetic tape, or unit-record equipment. This situation could arise when several types of data acquisition devices are feeding a centralized installation.
  • Bypassing restrictions imposed by the unavailability of I/O devices (for example, when devices on order have not been installed).
  • Assembling, testing, and debugging on one system or device type and processing on a different one. For example, an IBM 3380 Direct Access Storage drive can be used as a substitute for a magnetic tape unit.
  • Testing TSO commands such as REXX execs in the TSO/E background.

To make your program device independent, take the following actions:

  • Omit all device-dependent macros and parameters from your program. For maximum efficiency it is best to omit the BLKSIZE parameter with a BSAM, BPAM or QSAM DCB. See System-Determined Block Size.
  • Supply the parameters on your data definition (DD) statement, data class, or during the OPEN exit routine. That is, do not specify any required device-dependent parameters until the program is ready for execution. Your program can learn many of the device characteristics by issuing the DEVTYPE macro.

User Level Libraries − This provides simple interface to the user program to perform input and output. For example, stdio is a library provided by C and C++ programming languages.

  • Kernel Level Modules − This provides device driver to interact with the device controller and device independent I/O modules used by the device drivers.

  • Hardware − This layer includes actual hardware and hardware controller which interact with the device drivers and makes hardware alive.

  • A key concept in the design of I/O software is that it should be device independent where it should be possible to write programs that can access any I/O device without having to specify the device in advance. For example, a program that reads a file as input should be able to read a file on a floppy disk, on a hard disk, or on a CD-ROM, without having to modify the program for each different device.

    How is a device dependent program different from a device independent program?

    Device Drivers

    Device drivers are software modules that can be plugged into an OS to handle a particular device. Operating System takes help from device drivers to handle all I/O devices. Device drivers encapsulate device-dependent code and implement a standard interface in such a way that code contains device-specific register reads/writes. Device driver, is generally written by the device's manufacturer and delivered along with the device on a CD-ROM.

    A device driver performs the following jobs −

    • To accept request from the device independent software above to it.
    • Interact with the device controller to take and give I/O and perform required error handling
    • Making sure that the request is executed successfully

    How a device driver handles a request is as follows: Suppose a request comes to read a block N. If the driver is idle at the time a request arrives, it starts carrying out the request immediately. Otherwise, if the driver is already busy with some other request, it places the new request in the queue of pending requests.

    Interrupt handlers

    An interrupt handler, also known as an interrupt service routine or ISR, is a piece of software or more specifically a callback function in an operating system or more specifically in a device driver, whose execution is triggered by the reception of an interrupt.

    When the interrupt happens, the interrupt procedure does whatever it has to in order to handle the interrupt, updates data structures and wakes up process that was waiting for an interrupt to happen.

    The interrupt mechanism accepts an address ─ a number that selects a specific interrupt handling routine/function from a small set. In most architectures, this address is an offset stored in a table called the interrupt vector table. This vector contains the memory addresses of specialized interrupt handlers.

    Device-Independent I/O Software

    The basic function of the device-independent software is to perform the I/O functions that are common to all devices and to provide a uniform interface to the user-level software. Though it is difficult to write completely device independent software but we can write some modules which are common among all the devices. Following is a list of functions of device-independent I/O Software −

    • Uniform interfacing for device drivers
    • Device naming - Mnemonic names mapped to Major and Minor device numbers
    • Device protection
    • Providing a device-independent block size
    • Buffering because data coming off a device cannot be stored in final destination.
    • Storage allocation on block devices
    • Allocation and releasing dedicated devices
    • Error Reporting

    User-Space I/O Software

    These are the libraries which provide richer and simplified interface to access the functionality of the kernel or ultimately interactive with the device drivers. Most of the user-level I/O software consists of library procedures with some exception like spooling system which is a way of dealing with dedicated I/O devices in a multiprogramming system.

    I/O Libraries (e.g., stdio) are in user-space to provide an interface to the OS resident device-independent I/O SW. For example putchar(), getchar(), printf() and scanf() are example of user level I/O library stdio available in C programming.

    Kernel I/O Subsystem

    Kernel I/O Subsystem is responsible to provide many services related to I/O. Following are some of the services provided.

    • Scheduling − Kernel schedules a set of I/O requests to determine a good order in which to execute them. When an application issues a blocking I/O system call, the request is placed on the queue for that device. The Kernel I/O scheduler rearranges the order of the queue to improve the overall system efficiency and the average response time experienced by the applications.

    • Buffering − Kernel I/O Subsystem maintains a memory area known as buffer that stores data while they are transferred between two devices or between a device with an application operation. Buffering is done to cope with a speed mismatch between the producer and consumer of a data stream or to adapt between devices that have different data transfer sizes.

    • Caching − Kernel maintains cache memory which is region of fast memory that holds copies of data. Access to the cached copy is more efficient than access to the original.

    • Spooling and Device Reservation − A spool is a buffer that holds output for a device, such as a printer, that cannot accept interleaved data streams. The spooling system copies the queued spool files to the printer one at a time. In some operating systems, spooling is managed by a system daemon process. In other operating systems, it is handled by an in kernel thread.

    • Error Handling − An operating system that uses protected memory can guard against many kinds of hardware and application errors.

      What is a device independent program?

      In short, device independence means that graphics application software is not bound to a particular manu- facturer's equipment. A device-independent application program, then, needs to be compiled only once. At execution time, the user chooses the particular device or devices to be run with the compiled program.

      What is a device dependent program?

      (adj.) Like machine-dependent, device-dependent refers to programs that can run only on a certain type of hardware (i.e., their ability to function depends on the devices on which they run).

      What does it mean to be independent in computer?

      In computing, an independent variable is any variable that changes its value under a process, program, event, or any computing-specific interaction. It is used in computer programming to be assigned to a variable value, entity or process, or to calculate the value of a dependent variable.

      Why is device independence important?

      Device independence is important to the File Manager because a software application shouldbe able to function on a wide variety of devices regardless of the local hardware on which thesoftware is used. If there is no independence to the file manager, the file cannot be managed.