Understanding operating systems 5th ed ch13

718 views
645 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
718
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
72
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Understanding operating systems 5th ed ch13

  1. 1. Understanding Operating Systems Fifth Edition Chapter 13 Unix Operating System
  2. 2. Learning Objectives <ul><li>The goals of UNIX designers </li></ul><ul><li>The significance of using files to manipulate devices </li></ul><ul><li>The strengths and weaknesses of having competing versions of UNIX </li></ul><ul><li>The advantages of command-driven user interfaces </li></ul><ul><li>The roles of the Memory, Processor, Device, and File Managers in UNIX </li></ul>Understanding Operating Systems, Fifth Edition
  3. 3. Overview <ul><li>Three major advantages of UNIX </li></ul><ul><ul><li>Portability </li></ul></ul><ul><ul><ul><li>Code written in high-level language (C language) </li></ul></ul></ul><ul><ul><li>Powerful utilities </li></ul></ul><ul><ul><ul><li>Brief, single operation commands </li></ul></ul></ul><ul><ul><ul><li>Combinable into single command </li></ul></ul></ul><ul><ul><li>Application device independence </li></ul></ul><ul><ul><ul><li>Configurable to operate on any device type </li></ul></ul></ul><ul><li>Disadvantage </li></ul><ul><ul><li>No single standardized version </li></ul></ul><ul><ul><li>Brief, cryptic commands difficult for novice learner </li></ul></ul>Understanding Operating Systems, Fifth Edition
  4. 4. History <ul><li>Research project originally in 1965 </li></ul><ul><ul><li>Joint venture between Bell Labs, AT&T, General Electric, and MIT </li></ul></ul><ul><li>Goal </li></ul><ul><ul><li>Develop MULTICS for GE-645 mainframe </li></ul></ul><ul><li>MULTICS ambition </li></ul><ul><ul><li>Serve diverse user group needs </li></ul></ul><ul><ul><ul><li>Too intricate, complex, large for commercial value </li></ul></ul></ul><ul><li>Bell labs withdrew in 1969 </li></ul><ul><li>Ken Thompson and Dennis Ritchie continued the project </li></ul>Understanding Operating Systems, Fifth Edition
  5. 5. History (continued) Understanding Operating Systems, Fifth Edition
  6. 6. The Evolution of Unix <ul><li>Original language </li></ul><ul><ul><li>DEC PDP-7 assembly language </li></ul></ul><ul><li>First official version: 1971 </li></ul><ul><ul><li>Design </li></ul></ul><ul><ul><ul><li>Do one thing well </li></ul></ul></ul><ul><ul><li>Ran on DEC PDP-11 </li></ul></ul><ul><ul><li>No pipes or filters </li></ul></ul><ul><ul><ul><li>Added in version 2 </li></ul></ul></ul><ul><li>Thompson and Ritchie: version 3 </li></ul><ul><ul><li>New programming language (C language) </li></ul></ul>Understanding Operating Systems, Fifth Edition
  7. 7. The Evolution of Unix (continued) <ul><li>AT&T forbidden to sell software </li></ul><ul><ul><li>Universities and developers advanced software </li></ul></ul><ul><ul><ul><li>Commercial transformation </li></ul></ul></ul><ul><ul><ul><li>Berkley BSD version: 1973-1975 </li></ul></ul></ul><ul><li>1984: government deregulation </li></ul><ul><ul><li>AT&T personal computer with UNIX System 4 </li></ul></ul><ul><ul><ul><li>Contained additional Berkley version features </li></ul></ul></ul><ul><ul><ul><li>AT&T System 4 promotion as standard fails </li></ul></ul></ul><ul><li>1990: two dozen versions </li></ul>Understanding Operating Systems, Fifth Edition
  8. 8. The Evolution of Unix (continued) <ul><li>1991: AT&T UNIX system laboratories </li></ul><ul><ul><li>Develops System V release 4 </li></ul></ul><ul><ul><li>Features </li></ul></ul><ul><ul><ul><li>System V release 3, BSD 4.3, SunOS, Xenix </li></ul></ul></ul><ul><li>“ The Open Group” formed </li></ul><ul><ul><li>Owns UNIX trademark </li></ul></ul><ul><li>1993: Berkeley </li></ul><ul><ul><li>4.4 BSD: based on AT&T’s UNIX (AT&T license) </li></ul></ul><ul><ul><li>Novell acquires UNIX from AT&T </li></ul></ul>Understanding Operating Systems, Fifth Edition
  9. 9. The Evolution of Unix (continued) <ul><li>Current releases </li></ul><ul><ul><li>Modify “do one thing well” position </li></ul></ul><ul><ul><li>Commands more difficult to use </li></ul></ul><ul><ul><ul><li>Pipelines preserved </li></ul></ul></ul><ul><ul><li>Adaptable to new situations with ease </li></ul></ul><ul><ul><ul><li>Meet new user needs </li></ul></ul></ul><ul><ul><li>Full local area network support </li></ul></ul><ul><ul><li>Comply with international standards </li></ul></ul><ul><ul><li>Security improved </li></ul></ul><ul><ul><li>Uses Common Desktop Environment (CDE) </li></ul></ul><ul><ul><li>ISO/IEC 9945:2003 Standard </li></ul></ul>Understanding Operating Systems, Fifth Edition
  10. 10. Design Goals <ul><li>Thompson and Ritchie vision </li></ul><ul><ul><li>UNIX operating system </li></ul></ul><ul><ul><ul><li>Created by programmers for programmers </li></ul></ul></ul><ul><ul><li>Fast, flexible, easy-to-use </li></ul></ul><ul><li>Immediate goals </li></ul><ul><ul><li>Support software development </li></ul></ul><ul><ul><ul><li>Included utilities for customized code </li></ul></ul></ul><ul><ul><ul><li>Utilities designed for simplicity: do one thing well </li></ul></ul></ul><ul><ul><ul><li>Small manageable sections of code </li></ul></ul></ul><ul><ul><li>Keep algorithms simple </li></ul></ul><ul><ul><ul><li>Based on simplicity, not sophistication </li></ul></ul></ul>Understanding Operating Systems, Fifth Edition
  11. 11. Design Goals (continued) <ul><li>Long-term goal </li></ul><ul><ul><li>Portability </li></ul></ul><ul><ul><ul><li>Reduces conversion costs </li></ul></ul></ul><ul><ul><ul><li>Application packages not obsolete </li></ul></ul></ul><ul><ul><li>Achieved with UNIX version 4 </li></ul></ul><ul><ul><ul><li>Hardware independent </li></ul></ul></ul><ul><li>POSIX </li></ul><ul><ul><li>Portable operating system interface for computer environments </li></ul></ul><ul><ul><ul><li>IEEE standards defining portable operating system interface </li></ul></ul></ul><ul><ul><ul><li>IEEE STD. 1003.1 (2004 edition) </li></ul></ul></ul>Understanding Operating Systems, Fifth Edition
  12. 12. Memory Management <ul><li>Multiprogramming systems </li></ul><ul><ul><li>Swapping (small jobs) </li></ul></ul><ul><ul><ul><li>Entire program in main memory before execution </li></ul></ul></ul><ul><ul><ul><li>Program size restriction </li></ul></ul></ul><ul><ul><ul><li>Round robin policy </li></ul></ul></ul><ul><ul><li>Demand paging (large jobs) </li></ul></ul><ul><ul><ul><li>More complicated hardware </li></ul></ul></ul><ul><ul><ul><li>Increases system overhead </li></ul></ul></ul><ul><ul><ul><li>Thrashing (under heavy loads) </li></ul></ul></ul><ul><ul><ul><li>Advantage: implements virtual memory concept </li></ul></ul></ul>Understanding Operating Systems, Fifth Edition
  13. 13. Memory Management (continued) <ul><li>Typical internal memory layout (single user) </li></ul><ul><ul><li>Program code </li></ul></ul><ul><ul><li>Data segment </li></ul></ul><ul><ul><li>Stack </li></ul></ul>Understanding Operating Systems, Fifth Edition
  14. 14. Memory Management (continued) <ul><li>Program code </li></ul><ul><ul><li>Sharable portion of program </li></ul></ul><ul><ul><li>Reentrant code </li></ul></ul><ul><ul><ul><li>Physically shared by several processes </li></ul></ul></ul><ul><ul><ul><li>Code protected: instructions not modified during normal execution </li></ul></ul></ul><ul><ul><ul><li>Data references: without absolute physical address </li></ul></ul></ul><ul><ul><li>Space allocation </li></ul></ul><ul><ul><ul><li>Program cannot release until all processes completed </li></ul></ul></ul><ul><ul><ul><li>Text table: tracks processes using program code </li></ul></ul></ul>Understanding Operating Systems, Fifth Edition
  15. 15. Memory Management (continued) <ul><li>Data segment </li></ul><ul><ul><li>After program code </li></ul></ul><ul><ul><ul><li>Grows toward higher memory locations </li></ul></ul></ul><ul><ul><li>Nonsharable section of memory </li></ul></ul><ul><li>Stack </li></ul><ul><ul><li>Starts at highest memory address </li></ul></ul><ul><ul><ul><li>Grows downward </li></ul></ul></ul><ul><ul><ul><li>Subroutine calls and interrupts add information </li></ul></ul></ul><ul><ul><ul><li>Main memory </li></ul></ul></ul><ul><ul><ul><li>Process information saved when process interrupted </li></ul></ul></ul><ul><ul><li>Nonsharable section of memory </li></ul></ul>Understanding Operating Systems, Fifth Edition
  16. 16. Memory Management (continued) <ul><li>UNIX kernel </li></ul><ul><ul><li>Implements “system calls” </li></ul></ul><ul><ul><ul><li>Memory boundaries for process coexistence </li></ul></ul></ul><ul><ul><li>System calls </li></ul></ul><ul><ul><ul><li>File Manager interaction and request of I/O services </li></ul></ul></ul><ul><ul><li>Implements most primitive system functions </li></ul></ul><ul><ul><ul><li>Permanently resides in memory </li></ul></ul></ul><ul><ul><li>Uses LRU page replacement algorithm </li></ul></ul><ul><li>Network PCs, single-user, and multi-user systems </li></ul><ul><ul><li>Use same memory management concepts </li></ul></ul>Understanding Operating Systems, Fifth Edition
  17. 17. Process Management <ul><li>Handles </li></ul><ul><ul><li>CPU allocation </li></ul></ul><ul><ul><li>Process scheduling </li></ul></ul><ul><ul><li>Satisfaction of process requests </li></ul></ul><ul><li>Kernel maintains tables </li></ul><ul><ul><li>Coordinates process execution </li></ul></ul><ul><ul><li>Device allocation </li></ul></ul><ul><li>Uses predefined policies </li></ul><ul><ul><li>Select process from READY queue </li></ul></ul><ul><ul><li>Begin execution </li></ul></ul><ul><ul><ul><li>Give time slice </li></ul></ul></ul>Understanding Operating Systems, Fifth Edition
  18. 18. Process Management (continued) <ul><li>Process scheduling algorithm </li></ul><ul><ul><li>Selects highest priority process to run first </li></ul></ul><ul><ul><li>Priority value: accumulated CPU time </li></ul></ul><ul><ul><ul><li>Processes with large CPU time get lower priority </li></ul></ul></ul><ul><ul><li>Compute-to-total-time ratio </li></ul></ul><ul><ul><ul><li>System updates for each job every second </li></ul></ul></ul><ul><ul><ul><li>Total time process in system divided by used process CPU time </li></ul></ul></ul><ul><ul><li>Ratio = one </li></ul></ul><ul><ul><ul><li>CPU-bound job </li></ul></ul></ul>Understanding Operating Systems, Fifth Edition
  19. 19. Process Management (continued) <ul><li>Process scheduling algorithm (continued) </li></ul><ul><ul><li>Processes with same computed priority </li></ul></ul><ul><ul><ul><li>Handled by round robin </li></ul></ul></ul><ul><ul><li>Interactive processes: low ratio (no special policies) </li></ul></ul><ul><ul><li>Balance I/O-bound jobs with CPU-bound jobs </li></ul></ul><ul><ul><ul><li>Keeps processor busy </li></ul></ul></ul><ul><ul><ul><li>Minimizes waiting processes overhead </li></ul></ul></ul>Understanding Operating Systems, Fifth Edition
  20. 20. Process Management (continued) <ul><li>Process scheduling algorithm (continued) </li></ul><ul><ul><li>Loading process from READY queue </li></ul></ul><ul><ul><ul><li>Process with longest secondary storage time </li></ul></ul></ul><ul><ul><li>Swap out process </li></ul></ul><ul><ul><ul><li>Process waiting longest (disk I/O, idle ) </li></ul></ul></ul><ul><ul><li>When processor becomes available </li></ul></ul><ul><ul><ul><li>Process selected may not be ready (waiting on I/O) </li></ul></ul></ul><ul><ul><ul><li>Determine inactive but ready for execution </li></ul></ul></ul><ul><ul><ul><li>Process priorities recalculated </li></ul></ul></ul><ul><ul><ul><li>Handled dynamically </li></ul></ul></ul>Understanding Operating Systems, Fifth Edition
  21. 21. Process Table Versus User Table <ul><li>Simple processes (nonsharable code) </li></ul><ul><li>Tables </li></ul><ul><ul><li>Keep system running smoothly </li></ul></ul><ul><li>Process table </li></ul><ul><ul><li>Always resides in memory </li></ul></ul><ul><ul><li>Maintains text table </li></ul></ul><ul><li>User table </li></ul><ul><ul><li>Resides in memory while process is active </li></ul></ul><ul><ul><li>User table, process data segment, code segment </li></ul></ul><ul><ul><ul><li>Swapped as needed </li></ul></ul></ul>Understanding Operating Systems, Fifth Edition
  22. 22. Understanding Operating Systems, Fifth Edition
  23. 23. Process Table Versus User Table (continued) <ul><li>Process table </li></ul><ul><li>Each entry contains: </li></ul><ul><ul><li>Process identification number </li></ul></ul><ul><ul><li>User identification number </li></ul></ul><ul><ul><li>Process memory address or secondary storage address </li></ul></ul><ul><ul><li>Process size and scheduling information </li></ul></ul><ul><li>Set up when process is created </li></ul><ul><li>Deleted when process terminates </li></ul>Understanding Operating Systems, Fifth Edition
  24. 24. Process Table Versus User Table (continued) <ul><li>Text table </li></ul><ul><ul><li>Sharable code processes </li></ul></ul><ul><ul><li>Process table maintains </li></ul></ul><ul><li>Contains: </li></ul><ul><ul><li>Memory address or secondary storage address of text segment (sharable code) </li></ul></ul><ul><ul><li>Count: tracks number of processes using code </li></ul></ul><ul><ul><ul><li>Increased by one when process starts using code </li></ul></ul></ul><ul><ul><ul><li>Decreased by one when process stops using code </li></ul></ul></ul><ul><ul><ul><li>Count = 0: implies code no longer needed </li></ul></ul></ul>Understanding Operating Systems, Fifth Edition
  25. 25. Process Table Versus User Table (continued) <ul><li>User table </li></ul><ul><ul><li>Allocated to each active process </li></ul></ul><ul><ul><li>Stored in transient memory area </li></ul></ul><ul><li>Contains: </li></ul><ul><ul><li>User and group identification numbers </li></ul></ul><ul><ul><ul><li>Determine file access privileges </li></ul></ul></ul><ul><ul><li>Pointers to system’s file table </li></ul></ul><ul><ul><ul><li>Every file process uses </li></ul></ul></ul><ul><ul><li>Pointer to current directory </li></ul></ul><ul><ul><li>List of responses for various interrupts </li></ul></ul><ul><ul><li>All information accessible when process running </li></ul></ul>Understanding Operating Systems, Fifth Edition
  26. 26. Synchronization <ul><li>UNIX </li></ul><ul><ul><li>True multitasking operating system </li></ul></ul><ul><li>Requires processes wait for certain events </li></ul><ul><ul><li>Each event represented by integers </li></ul></ul><ul><ul><ul><li>Equal to address of table associated with event </li></ul></ul></ul><ul><li>Race occurs </li></ul><ul><ul><li>Event happens during process transition decision </li></ul></ul><ul><ul><ul><li>Wait for event and entering WAIT state </li></ul></ul></ul>Understanding Operating Systems, Fifth Edition
  27. 27. Synchronization (continued) <ul><li>fork </li></ul><ul><ul><li>Execute one program from another program </li></ul></ul><ul><ul><li>Second program </li></ul></ul><ul><ul><ul><li>Given all first program attributes (open files) </li></ul></ul></ul><ul><ul><li>Save first program in original form </li></ul></ul><ul><ul><li>Split program: two copies </li></ul></ul><ul><ul><ul><li>Both run from statement after fork command </li></ul></ul></ul><ul><ul><li>fork executed </li></ul></ul><ul><ul><ul><li>“ Process id” (pid) generated </li></ul></ul></ul><ul><ul><ul><li>Ensure each process has unique ID number </li></ul></ul></ul>Understanding Operating Systems, Fifth Edition
  28. 28. Synchronization (continued) Understanding Operating Systems, Fifth Edition
  29. 29. Synchronization (continued) <ul><li>wait </li></ul><ul><ul><li>Synchronize process execution </li></ul></ul><ul><ul><ul><li>Suspend parent until child finished </li></ul></ul></ul><ul><ul><li>Program IF-THEN-ELSE structure </li></ul></ul><ul><ul><ul><li>Controlled by pid value </li></ul></ul></ul><ul><ul><ul><li>pid > zero: parent process </li></ul></ul></ul><ul><ul><ul><li>pid = zero: child process </li></ul></ul></ul><ul><ul><ul><li>pid < zero: error in fork call </li></ul></ul></ul>Understanding Operating Systems, Fifth Edition
  30. 30. Synchronization (continued) Understanding Operating Systems, Fifth Edition
  31. 31. Synchronization (continued) <ul><li>exec </li></ul><ul><ul><li>Start new program execution from another program </li></ul></ul><ul><ul><ul><li>execl, execv, execls, execlp, and execvp </li></ul></ul></ul><ul><ul><li>Successful exec call </li></ul></ul><ul><ul><ul><li>Overlay second program over first </li></ul></ul></ul><ul><ul><ul><li>Only second program in memory </li></ul></ul></ul><ul><ul><li>No return from successful exec call </li></ul></ul><ul><ul><ul><li>Parent-child concept: does not hold </li></ul></ul></ul><ul><ul><li>Each exec call </li></ul></ul><ul><ul><ul><li>Followed by test ensuring successful completion </li></ul></ul></ul>Understanding Operating Systems, Fifth Edition
  32. 32. Synchronization (continued) Understanding Operating Systems, Fifth Edition
  33. 33. Device Management <ul><li>Device independence to applications </li></ul><ul><ul><li>I/O device treated as special file type </li></ul></ul><ul><li>Device files given name </li></ul><ul><ul><li>Descriptors called “iodes” </li></ul></ul><ul><ul><ul><li>Identifies devices, contains device information, stored in device directory </li></ul></ul></ul><ul><li>Device drivers </li></ul><ul><ul><li>Subroutines working with operating system </li></ul></ul><ul><ul><li>Supervise data transmission </li></ul></ul><ul><ul><ul><li>Between main memory and peripheral unit </li></ul></ul></ul><ul><ul><li>Most common drivers included in UNIX </li></ul></ul>Understanding Operating Systems, Fifth Edition
  34. 34. Device Management (continued) <ul><li>Device driver kernel incorporation </li></ul><ul><ul><li>During system configuration </li></ul></ul><ul><li>Recent UNIX versions </li></ul><ul><ul><li>Program called config </li></ul></ul><ul><ul><li>Automatically create s conf.c </li></ul></ul><ul><ul><ul><li>For any hardware configuration </li></ul></ul></ul><ul><ul><li>conf.c contains parameters controlling resources </li></ul></ul><ul><ul><ul><li>Number of internal kernel buffers and swap space size </li></ul></ul></ul><ul><ul><li>conf.c contains two tables </li></ul></ul><ul><ul><ul><li>bdevsw (“block I/O switch”) </li></ul></ul></ul><ul><ul><ul><li>cdevsw (“character I/O switch”) </li></ul></ul></ul>Understanding Operating Systems, Fifth Edition
  35. 35. Device Classifications <ul><li>Divide I/O system </li></ul><ul><ul><li>“ Block I/O” system (“structured I/O” system) </li></ul></ul><ul><ul><li>“ Character I/O” system (“unstructured I/O” system) </li></ul></ul><ul><li>Physical device identification </li></ul><ul><ul><li>Minor device number </li></ul></ul><ul><ul><li>Major device number </li></ul></ul><ul><ul><li>Class: block or character </li></ul></ul>Understanding Operating Systems, Fifth Edition
  36. 36. Device Classifications (continued) Understanding Operating Systems, Fifth Edition
  37. 37. Device Classifications (continued) <ul><li>Class: block or character </li></ul><ul><ul><li>Each has configuration table </li></ul></ul><ul><ul><ul><li>Array of entry points into device drivers </li></ul></ul></ul><ul><ul><li>Major device number </li></ul></ul><ul><ul><ul><li>Index to array to access appropriate code (specific driver) </li></ul></ul></ul><ul><ul><li>Minor device number </li></ul></ul><ul><ul><ul><li>Passed as an argument to device driver </li></ul></ul></ul><ul><ul><ul><li>Access one of several identical physical devices </li></ul></ul></ul><ul><ul><li>Block I/O system </li></ul></ul><ul><ul><ul><li>Devices addressed as 512-byte block sequences </li></ul></ul></ul><ul><ul><ul><li>Allows device manager to buffer (reduce I/O traffic) </li></ul></ul></ul>Understanding Operating Systems, Fifth Edition
  38. 38. Device Classifications (continued) <ul><li>Character class devices </li></ul><ul><ul><li>Device drivers handle implementing character lists </li></ul></ul><ul><ul><li>Example: terminal </li></ul></ul><ul><ul><ul><li>Typical character device </li></ul></ul></ul><ul><ul><ul><li>Two input queues and one output queue </li></ul></ul></ul><ul><li>I/O procedure synchronized through hardware completion interrupts </li></ul><ul><li>Some devices belong to both classes </li></ul><ul><ul><li>Examples: disk drives, tape drives </li></ul></ul>Understanding Operating Systems, Fifth Edition
  39. 39. Device Drivers <ul><li>Special section in kernel </li></ul><ul><ul><li>Includes instructions </li></ul></ul><ul><ul><ul><li>Allows operating system communication with device </li></ul></ul></ul><ul><li>Disk drive’s device drivers </li></ul><ul><ul><li>Use seek strategy to minimize arm movement </li></ul></ul><ul><li>Kept in set of files </li></ul><ul><ul><li>Loaded as needed </li></ul></ul><ul><ul><ul><li>Case of seldom used devices </li></ul></ul></ul><ul><ul><li>Kept in memory all the time </li></ul></ul><ul><ul><ul><li>Loaded at boot time </li></ul></ul></ul><ul><ul><li>Kept in /dev directory by default and convention </li></ul></ul>Understanding Operating Systems, Fifth Edition
  40. 40. File Management <ul><li>Three file types </li></ul><ul><ul><li>Directories </li></ul></ul><ul><ul><li>Ordinary files </li></ul></ul><ul><ul><li>Special files </li></ul></ul><ul><li>Each enjoys certain privileges </li></ul><ul><li>Directories </li></ul><ul><ul><li>Maintain hierarchical structure of file system </li></ul></ul><ul><ul><li>Users allowed to read information in directory files </li></ul></ul><ul><ul><li>Only system allowed directory file modification </li></ul></ul>Understanding Operating Systems, Fifth Edition
  41. 41. File Management (continued) <ul><li>Ordinary files </li></ul><ul><ul><li>Users store information </li></ul></ul><ul><ul><li>Protection based on user requests </li></ul></ul><ul><ul><ul><li>Related to read, write, execute, delete functions performed on file </li></ul></ul></ul><ul><li>Special files </li></ul><ul><ul><li>Device drivers providing I/O hardware interface </li></ul></ul><ul><ul><li>Appear as entries in directories </li></ul></ul><ul><ul><li>Part of file system (most in /dev directory) </li></ul></ul><ul><ul><li>Special filename indicates type of device association </li></ul></ul>Understanding Operating Systems, Fifth Edition
  42. 42. File Management (continued) <ul><li>Files stored as sequences of bytes </li></ul><ul><ul><li>No structure imposed </li></ul></ul><ul><li>Text files </li></ul><ul><ul><li>Character strings </li></ul></ul><ul><ul><ul><li>Lines delimited by line feed, new line, character </li></ul></ul></ul><ul><li>Binary files </li></ul><ul><ul><li>Sequences of binary digits </li></ul></ul><ul><ul><ul><li>Grouped into words as they appear in memory during program execution </li></ul></ul></ul><ul><li>Structure of files </li></ul><ul><ul><li>Controlled by programs using them: not by system </li></ul></ul>Understanding Operating Systems, Fifth Edition
  43. 43. File Management (continued) <ul><li>Organizes disk into blocks of 512 bytes each </li></ul><ul><li>Divides disk into four basic regions </li></ul><ul><ul><li>First region (address 0): reserved for booting </li></ul></ul><ul><ul><li>Second region: contains disk size and other regions’ boundaries </li></ul></ul><ul><ul><li>Third region includes: file definitions called “i-list” </li></ul></ul><ul><ul><li>Remaining region: free blocks available for file storage </li></ul></ul><ul><li>Files stored in contiguous empty blocks </li></ul><ul><ul><li>Simple allocation and no need to compact </li></ul></ul>Understanding Operating Systems, Fifth Edition
  44. 44. File Management (continued) <ul><li>“ i-node” </li></ul><ul><li>Each entry in i-list called an “i-node” (or inode) </li></ul><ul><ul><li>Contains 13 disk addresses </li></ul></ul><ul><li>Contains specific file information </li></ul><ul><ul><li>Owner’s identification </li></ul></ul><ul><ul><li>Protection bits, physical address, file size </li></ul></ul><ul><ul><li>Time of creation, last use, and last update </li></ul></ul><ul><ul><li>Number of links </li></ul></ul><ul><ul><li>File type </li></ul></ul><ul><ul><ul><li>Directory, ordinary file, or special file </li></ul></ul></ul>Understanding Operating Systems, Fifth Edition
  45. 45. File Naming Conventions <ul><li>Case-sensitive filenames </li></ul><ul><li>255 character length </li></ul><ul><li>No file naming conventions </li></ul><ul><ul><li>Some compilers expect specific suffixes </li></ul></ul><ul><li>Supports hierarchical tree file structure </li></ul><ul><ul><li>Root directory identified by slash (/) </li></ul></ul>Understanding Operating Systems, Fifth Edition
  46. 46. File Naming Conventions (continued) Understanding Operating Systems, Fifth Edition
  47. 47. File Naming Conventions (continued) <ul><li>Path name rules </li></ul><ul><ul><li>Path name starting with slash </li></ul></ul><ul><ul><ul><li>Root directory </li></ul></ul></ul><ul><ul><li>Path name </li></ul></ul><ul><ul><ul><li>One name or list of names: separated by slashes </li></ul></ul></ul><ul><ul><ul><li>Last name on list: filename requested </li></ul></ul></ul><ul><ul><li>Two periods (..) in path name </li></ul></ul><ul><ul><ul><li>Moves upward in hierarchy (closer to root ) </li></ul></ul></ul><ul><ul><ul><li>Only way to go up hierarchy </li></ul></ul></ul><ul><ul><ul><li>All other path names go down tree </li></ul></ul></ul><ul><ul><li>Spaces not allowed within path names </li></ul></ul>Understanding Operating Systems, Fifth Edition
  48. 48. Directory Listings <ul><li>“ long listing” </li></ul><ul><ul><li>Eight pieces of information for each file </li></ul></ul><ul><li>First column </li></ul><ul><ul><li>Shows file type and access privileges for each file </li></ul></ul><ul><ul><ul><li>First character: nature of file or directory </li></ul></ul></ul><ul><ul><ul><li>Next three characters: access privileges granted file owner </li></ul></ul></ul><ul><ul><ul><li>Next three characters: access privileges granted other user’s group members </li></ul></ul></ul><ul><ul><ul><li>Last three characters: access privileges granted to users at large (system-wide) </li></ul></ul></ul>Understanding Operating Systems, Fifth Edition
  49. 49. Directory Listings (continued) <ul><li>Second column </li></ul><ul><ul><li>Indicates number of links ( number of aliases ) </li></ul></ul><ul><ul><ul><li>Referring to same physical file </li></ul></ul></ul><ul><li>Aliases </li></ul><ul><ul><li>Important UNIX feature: support file sharing </li></ul></ul><ul><ul><ul><li>Several users work together on same project </li></ul></ul></ul><ul><ul><li>Shared files appear in different directories belonging to different users </li></ul></ul><ul><ul><li>Filename: may be different from directory to directory </li></ul></ul><ul><ul><li>Eventually number will indicate when file no longer needed: can be deleted </li></ul></ul>Understanding Operating Systems, Fifth Edition
  50. 50. Directory Listings (continued) Understanding Operating Systems, Fifth Edition
  51. 51. Data Structures <ul><li>File descriptors divided into parts </li></ul><ul><ul><li>Hierarchical directories </li></ul></ul><ul><ul><ul><li>Contain filename and i-number </li></ul></ul></ul><ul><ul><ul><li>Pointer to another location: i-node </li></ul></ul></ul><ul><ul><li>i-node </li></ul></ul><ul><ul><ul><li>Contains rest of information </li></ul></ul></ul><ul><ul><li>i-nodes stored in reserved part of device </li></ul></ul><ul><ul><ul><li>Where directory resides </li></ul></ul></ul><ul><ul><li>i-node has 13 pointers (0–12) </li></ul></ul>Understanding Operating Systems, Fifth Edition
  52. 52. Data Structures (continued) Understanding Operating Systems, Fifth Edition
  53. 53. Data Structures (continued) <ul><li>When file opened </li></ul><ul><ul><li>Device, i-number, read/write pointer stored in system file table and indexed by i-node </li></ul></ul><ul><li>When file created </li></ul><ul><ul><li>i-node allocated to it </li></ul></ul><ul><ul><li>Directory entry with filename and i-node number created </li></ul></ul>Understanding Operating Systems, Fifth Edition
  54. 54. Data Structures (continued) <ul><li>When file linked </li></ul><ul><ul><li>Directory entry created with new name </li></ul></ul><ul><ul><li>Original i-node number and link-count field in the i-node incremented by one </li></ul></ul><ul><li>When shared file deleted </li></ul><ul><ul><li>Link-count field in i-node decremented by one </li></ul></ul><ul><ul><li>When count reaches zero </li></ul></ul><ul><ul><ul><li>Directory entry erased </li></ul></ul></ul><ul><ul><ul><li>Deallocate all disk blocks and allocate i-node block to file </li></ul></ul></ul>Understanding Operating Systems, Fifth Edition
  55. 55. User Interface <ul><li>Command-driven system </li></ul><ul><li>User commands </li></ul><ul><ul><li>Very short </li></ul></ul><ul><ul><ul><li>One character or a group of characters (acronym) </li></ul></ul></ul><ul><ul><li>Cannot be abbreviated or spelled out </li></ul></ul><ul><ul><li>Must be in correct case </li></ul></ul><ul><li>System prompt very economical </li></ul><ul><ul><li>Only one character: ($) or (%) </li></ul></ul><ul><li>Error messages quite brief </li></ul>Understanding Operating Systems, Fifth Edition
  56. 56. User Interface (continued) Understanding Operating Systems, Fifth Edition
  57. 57. User Interface (continued) <ul><li>General syntax of commands </li></ul><ul><ul><li>command arguments file_name </li></ul></ul><ul><li>“ command” </li></ul><ul><ul><li>Any legal operating system command </li></ul></ul><ul><ul><ul><li>Interpreted and executed by shell </li></ul></ul></ul><ul><li>“ arguments“ </li></ul><ul><ul><li>Required for some commands, optional for others </li></ul></ul><ul><li>“ file_name” </li></ul><ul><ul><li>Relative or absolute path name </li></ul></ul>Understanding Operating Systems, Fifth Edition
  58. 58. User Interface (continued) Understanding Operating Systems, Fifth Edition
  59. 59. Script Files <ul><li>Automate repetitious tasks </li></ul><ul><ul><li>Command files </li></ul></ul><ul><ul><ul><li>Often called shell files or script files </li></ul></ul></ul><ul><li>Each line of file </li></ul><ul><ul><li>Valid instruction </li></ul></ul><ul><ul><ul><li>Executed by typing sh and script file name </li></ul></ul></ul><ul><li>Also execute d by defining file as executable command </li></ul><ul><ul><li>Type filename at system prompt </li></ul></ul>Understanding Operating Systems, Fifth Edition
  60. 60. Script Files (continued) <ul><li>Script file example </li></ul><ul><ul><li>setenv DBPATH /u/lumber:.:/zdlf/product/central/db </li></ul></ul><ul><ul><li>setenv TERMCAP $INFODIR/etc/termcap </li></ul></ul><ul><ul><li>stty erase `^H’ </li></ul></ul><ul><ul><li>set savehistory </li></ul></ul><ul><ul><li>set history=20 </li></ul></ul><ul><ul><li>alias h history </li></ul></ul><ul><ul><li>alias 4gen infogen -f </li></ul></ul><ul><ul><li>setenv PATH /usr/info/bin:/etc </li></ul></ul>Understanding Operating Systems, Fifth Edition
  61. 61. Redirection <ul><li>Send output to file or another device </li></ul><ul><ul><li>Symbol : > ( between command and destination ) </li></ul></ul><ul><ul><li>Examples: </li></ul></ul><ul><ul><ul><li>ls > myfiles </li></ul></ul></ul><ul><ul><ul><li>cat chapt1 chapt2 > sectiona, </li></ul></ul></ul><ul><ul><ul><li>cat chapt* > sectiona </li></ul></ul></ul><ul><ul><li>Symbol >> appends new file to an existing file </li></ul></ul><ul><ul><li>Examples: </li></ul></ul><ul><ul><ul><li>cat chapt1 chapt2 >> sectiona </li></ul></ul></ul><ul><ul><ul><li>cat chapt* >> sectiona </li></ul></ul></ul>Understanding Operating Systems, Fifth Edition
  62. 62. Redirection (continued) <ul><li>Reverse redirection (<) </li></ul><ul><ul><li>Takes input for program from existing file instead of keyboard </li></ul></ul><ul><ul><li>Example: </li></ul></ul><ul><ul><ul><li>mail ann roger < memo </li></ul></ul></ul>Understanding Operating Systems, Fifth Edition
  63. 63. Redirection (continued) <ul><li>Redirection (>) </li></ul><ul><ul><li>Combined with system commands to achieve any desired results </li></ul></ul><ul><ul><li>Example : who > temporary </li></ul></ul><ul><ul><ul><li>Store in “temporary” file: all user names logged on </li></ul></ul></ul><ul><li>Interpretation of < and > </li></ul><ul><ul><li>Carried out by shell </li></ul></ul><ul><ul><li>Not by individual program </li></ul></ul><ul><li>Input and output redirection </li></ul><ul><ul><li>Used with any program </li></ul></ul>Understanding Operating Systems, Fifth Edition
  64. 64. Pipes <ul><li>Provide possibility to redirect output or input to selected files or devices </li></ul><ul><ul><li>Connect output from one program to input of another </li></ul></ul><ul><ul><li>No need for temporary or intermediate files </li></ul></ul><ul><ul><li>Example: who | sort </li></ul></ul><ul><li>Pipeline </li></ul><ul><ul><li>Several programs simultaneously processing same I/O stream </li></ul></ul><ul><ul><li>Example: who | sort | lpr </li></ul></ul>Understanding Operating Systems, Fifth Edition
  65. 65. Filters <ul><li>Program </li></ul><ul><ul><li>Read some input, manipulate it, generate output </li></ul></ul><ul><ul><li>wc (word count): </li></ul></ul><ul><ul><ul><li>Example: wc journal </li></ul></ul></ul><ul><ul><ul><li>System response: 10 140 700 </li></ul></ul></ul><ul><ul><ul><li>File journal has 10 lines, 140 words, 700 characters </li></ul></ul></ul><ul><ul><li>sort: Contents of file sorted and displayed on screen </li></ul></ul><ul><ul><ul><li>Example: sort sortednames </li></ul></ul></ul>Understanding Operating Systems, Fifth Edition
  66. 66. Filters (continued) <ul><li>Sort list in alphabetical order ignoring letter case </li></ul><ul><ul><li>sort –f > sortednames </li></ul></ul><ul><li>Obtain numerical sort in ascending order </li></ul><ul><ul><li>sort -n > sortednums </li></ul></ul><ul><li>Obtain numerical sort in descending order </li></ul><ul><ul><li>sort -nr > sortednums </li></ul></ul>Understanding Operating Systems, Fifth Edition
  67. 67. Additional Commands <ul><li>man </li></ul><ul><ul><li>Displays operating system online manual </li></ul></ul><ul><ul><li>Example: man cmp </li></ul></ul><ul><ul><ul><li>Displays page for compare (cmp) command </li></ul></ul></ul><ul><li>grep </li></ul><ul><ul><li>“ global regular expression and print” </li></ul></ul><ul><ul><li>Look for specific character patterns </li></ul></ul><ul><ul><li>Examples: </li></ul></ul><ul><ul><ul><li>grep Pittsburgh maillist </li></ul></ul></ul><ul><ul><ul><li>grep -v Pittsburgh maillist </li></ul></ul></ul><ul><ul><ul><li>grep -c Pittsburgh maillist </li></ul></ul></ul>Understanding Operating Systems, Fifth Edition
  68. 68. Additional Commands (continued) <ul><li>grep (continued) </li></ul><ul><ul><li>Can be combined with who command </li></ul></ul><ul><ul><li>Example: who | grep sam </li></ul></ul><ul><ul><ul><li>Sam’s name, device, date and time he logged in </li></ul></ul></ul><ul><ul><li>Example: ls -l / | grep '^d‘ </li></ul></ul><ul><ul><ul><li>Displays subdirectories list (not files) in root directory </li></ul></ul></ul><ul><li>nohup </li></ul><ul><ul><li>Log off the system without program completion </li></ul></ul><ul><ul><li>Example: </li></ul></ul><ul><ul><ul><li>nohup cp oldlargefile newlargefile and </li></ul></ul></ul>Understanding Operating Systems, Fifth Edition
  69. 69. Additional Commands (continued) <ul><li>nice </li></ul><ul><ul><li>Allows lowering program priority </li></ul></ul><ul><ul><li>Example: </li></ul></ul><ul><ul><li>nice cp oldlargefile newlargefile and </li></ul></ul>Understanding Operating Systems, Fifth Edition
  70. 70. Summary <ul><li>UNIX: major force in operating system field </li></ul><ul><ul><li>Written by programmers for programmers </li></ul></ul><ul><ul><li>Quite popular among programmers </li></ul></ul><ul><li>Advantages </li></ul><ul><ul><li>Spare user interface, device independence, portability, lack of verbosity, powerful command combinations </li></ul></ul><ul><li>Disadvantages </li></ul><ul><ul><li>Learning command-driven interface, brief commands </li></ul></ul><ul><li>Graphical interface and point-and-click surfacing </li></ul>Understanding Operating Systems, Fifth Edition

×