Docstoc

UNIX and LINUX

Document Sample
UNIX and LINUX Powered By Docstoc
					    UNIX and LINUX ‫פעמי עתידים‬
    ‫מר דב בלום מכללת עמל, באר שבע‬
1 History of UNIX
2 Overview of UNIX
3 Processes in UNIX
4 Memory management in UNIX
5 Input/output in UNIX
6 The UNIX file system
7 Security in UNIX
       Unix and Linux IO (Section 5) Mr. Dov Bloom Amal College of Technology
                                                                                1
                               Sockets
• Used in I/O networking (from Berkeley
  UNIX)
• Created dynamically
• Allow process to connect to a stream or
  device
• Like a phone socket – standard connection
• Creating a socket returns FD (file
  descriptor)
• Creates something like a “pipe”
        Unix and Linux IO (Section 5) Mr. Dov Bloom Amal College of Technology
                                                                                 2
                                 Sockets
• Each socket supports a specific kind of
  network
  – Reliable byte stream
  – Reliable packet stream
  – Unreliable packet stream
• Protocols:
  – TCP Transmission Control Protocol (byte stream)
  – UDP User Datagram Protocol (unreliable packet stream)
  – Various reliable packet protocols (Sequin, bridges )
  – Both are above IP


          Unix and Linux IO (Section 5) Mr. Dov Bloom Amal College of Technology
                                                                                   3
                               Sockets
• Each socket has an address
  – 32 bit integers – 4 bytes or
  – 8 hexanumbers IPv4 dotted quad 168.92.23.4)
• IPv6 128 bits = 16 bytes
  –    2001:0db8:85a3:0000:0000:8a2e:0370:7334
  – Or 2001:db8: 85a3::          8a2e: 370:7334
  – 2001:db8:85a3::8a2e:370:7334




        Unix and Linux IO (Section 5) Mr. Dov Bloom Amal College of Technology
                                                                                 4
                               Sockets
• After socket has an address
  and is on both sides (both computers)
  – One side makes a listen call on the socket
    which creates a buffer and blocks
  – The other side makes a connect call gives the
    FD of the local socket and the address of the
    remote;
  – The remote accepts the call and the connection
    is made ( it works like a pipe)
  – Read and write using the FD
  – Close
        Unix and Linux IO (Section 5) Mr. Dov Bloom Amal College of Technology
                                                                                 5
                 Networking




     Use of sockets for networking
Unix and Linux IO (Section 5) Mr. Dov Bloom Amal College of Technology
                                                                         6
              Terminal Management
    The main POSIX calls for managing the terminal




      4 calls for setting speeds get/set i/o speed
2 calls for the special chars to erase a char or a line,
                         interrupt
         Unix and Linux IO (Section 5) Mr. Dov Bloom Amal College of Technology
                                                                                  7
                UNIX I/O (1)

1. 1 driver for each device type
2. major device number
3. purpose: separate most of OS from
hardware
4. OS has common interface with drivers
5. minor device number – if a few identical
devices

       Unix and Linux IO (Section 5) Mr. Dov Bloom Amal College of Technology
                                                                                8
                        UNIX I/O 2
• When a user accesses a special file, the file
  system determines the major and minor
  device numbers and whether it is a block or
  character special file
• Major device number is used to index into
  either bdevsw1 array for block special or
  cdevsw for character special files
• These structures contain pointers to the
  procedures to open the device, read, write
  etc.
• Next slide - some of the fields of a typical
  cdevsw table are shown
  1 Block device switch array
        Unix and Linux IO (Section 5) Mr. Dov Bloom Amal College of Technology
                                                                                 9
                                                                                     9
                      UNIX I/O (3)




Some of the fields of a typical cdevsw table (char devices)
         bdevsw is the table for (block devices)
            Major device # is index for table
  Adding a device in UNIX means adding a table entry
      Unix and Linux IO (Section 5) Mr. Dov Bloom Amal College of Technology
                                                                               10
                    UNIX I/O (4)

          Driver has 2 parts:
• Top part runs in caller’s mode and
  interfaces to system
• Bottom part runs in kernel mode
  and interfaces with hardware
• Drivers can make calls to kernel
  procedures
    Unix and Linux IO (Section 5) Mr. Dov Bloom Amal College of Technology
                                                                             11
                       UNIX I/O (5)

• Buffer Cache to minimize block reads
1. When any block (inode, directory, file )
   has to be read, the cache is checked
2. If block is not in cache, read from disk

•   Algorithm to control cache (limited space)
    1. Move newest read to head of cache
    2. Remove tail

       Unix and Linux IO (Section 5) Mr. Dov Bloom Amal College of Technology
                                                                                12
              UNIX I/O (6)




    The UNIX I/O system in BSD
Unix and Linux IO (Section 5) Mr. Dov Bloom Amal College of Technology
                                                                         13
                        UNIX I/O (7)

• Buffer Cache used for writes , too
• Any write is to the cache in RAM, not the
  disk!
• Every 30 seconds Linux pdflush daemon will
  write “dirty” blocks to disk
• pdflush daemon will flush block to disk if it
  stays too long (even if clean)


              What about char devices?
        Unix and Linux IO (Section 5) Mr. Dov Bloom Amal College of Technology
                                                                                 14
                     Streams - BSD
• c-list is a block of 64 chars, a count and a
  pointer to next block
• When a user reads from /dev/tty (StdIO) the
  chars got from c-list to kernel code called
  “line discipline” which can filter it into a
  “cooked” stream
• Writes are also “cooked” (tab -> spaces;
  LF/CR
• Process can ask for “raw” (eg to send data)
        Unix and Linux IO (Section 5) Mr. Dov Bloom Amal College of Technology
                                                                                 15
      Streams - System V




Unix and Linux IO (Section 5) Mr. Dov Bloom Amal College of Technology
                                                                         16
    Input/Output Implementation in Linux




Figure 10-22. The Linux I/O system showing one file system in detail.
           Unix and Linux IO (Section 5) Mr. Dov Bloom Amal College of Technology
                                                                                    17
       Linux Disk read scheduler
• I/O scheduler in Linux to minimize disk
  head movements
• Purpose: to reorder read/write requests

• Linus Elevator scheduler :
  – Doubly linked list
  – New entries put into sorted place in list



         Unix and Linux IO (Section 5) Mr. Dov Bloom Amal College of Technology
                                                                                  18
            Linux Disk read scheduler
• Linus Elevator scheduler :
    – Doubly linked list
    – New entries put into sorted place in list

• New Linux scheduler has “deadlines”
  because old one could cause starvation
  (0.5 seconds for read, 5 sec for write are
  defaults)
• if read/write deadline is almost up, it takes
  priority over linked list


              Unix and Linux IO (Section 5) Mr. Dov Bloom Amal College of Technology
                                                                                       19
  IO Modules in Unix and Linux
• Unix had staticly linked drivers in the
  kernel from the boot, since the IO
  devices didn’t change much
• Linux world – many more device
  available
• Linux – “loadable modules” can be
  added while kernel is running

      Unix and Linux IO (Section 5) Mr. Dov Bloom Amal College of Technology
                                                                               20
          IO Modules in Linux
• What needs to be done when an IO module
  is added?
  –Memory Relocation
  –set resources
  –set interrupts
  –add new device to major table
  –initialize device
      Unix and Linux IO (Section 5) Mr. Dov Bloom Amal College of Technology
                                                                               21

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:13
posted:7/24/2012
language:English
pages:21