TimeLinux1

Saturday, April 23, 2011

Linux: A closer look - IO Concepts

... continued ...

-In linux all IO is treated as file operations.
-in other words, IO devices are treated like files and accessed via the open, read, write and other file system calls.
-devices like printer, disks, terminals etc are listed as special files in /dev dir; eg /dev/lp for printer.
-eg: cp afile /dev/lp will print the file 'afile'. infact, cp is not even aware that it is printing.
-files can be regular or special files.
-special files can be block files or character files.
-block files are read one block at a time and can be accessed randonly.
-eg: its possible to jump directly to nth block of a block device file. usually they are used for disks.
-character files are used for devices that input or output character streams instead of blocks.
-eg: keyboards, printers, mice, etc.
-each special has a major device number and a minor device number.
-major device number refers to the driver and minor device number refers to the actual device that uses the driver.
-eg: if a disk driver supports two disks, then the two disk have the same major number but different minor number.
-the file type, major and minor numbers can be viewed in the ls -l output.

-another example of IO is networking as pioneered by Berkeley Unix and then adopted by Linux.
-the key concept here is that of socket.
-sockets can be treated as physical mailboxes on the wall where users interact with the postal system.
-similarly sockets allow you to access network services.
-sockets can be created and destroyed dynamically.
-sockets are created on both source and destn.
-the sender uses 'connect' system call, the receiver uses 'listen' system call.
-once the connection is no longer needed, it can be closed with the 'close' system call.
-socket creation returns a file descriptor which is needed for establishing a conn, reading data, writing and releasing conn.
-sockets can be:
    . reliable conn oriented byte stream        - send and receive follow the same order of bytes
    . reliable conn oriented packet stream        - like first one but preserves packet boundaries
    . unreliable packet transmission        - random order of packets for efficient transmission
-eg of reliable conn types    - tcp
-eg of unreliable conn type    - udp
-both tcp and udp are layered on top of ip.
-all three of these originated in arpanet (us dept of defense project) and led to the Internet of today.


No comments:

Post a Comment