Presentation is loading. Please wait.

Presentation is loading. Please wait.

Understanding Operating Systems Fifth Edition Chapter 13 Unix Operating System.

Similar presentations

Presentation on theme: "Understanding Operating Systems Fifth Edition Chapter 13 Unix Operating System."— Presentation transcript:

1 Understanding Operating Systems Fifth Edition Chapter 13 Unix Operating System

2 Understanding Operating Systems, Fifth Edition2 Learning Objectives The goals of UNIX designers The significance of using files to manipulate devices The strengths and weaknesses of having competing versions of UNIX The advantages of command-driven user interfaces The roles of the Memory, Processor, Device, and File Managers in UNIX

3 Understanding Operating Systems, Fifth Edition3 Overview Three major advantages of UNIX –Portability Code written in high-level language (C language) –Powerful utilities Brief, single operation commands Combinable into single command –Application device independence Configurable to operate on any device type Disadvantage –No single standardized version –Brief, cryptic commands difficult for novice learner

4 Understanding Operating Systems, Fifth Edition4 History Research project originally in 1965 –Joint venture between Bell Labs, AT&T, General Electric, and MIT Goal –Develop MULTICS for GE-645 mainframe MULTICS ambition –Serve diverse user group needs Too intricate, complex, large for commercial value Bell labs withdrew in 1969 Ken Thompson and Dennis Ritchie continued the project

5 Understanding Operating Systems, Fifth Edition5 History (continued)

6 Understanding Operating Systems, Fifth Edition6 The Evolution of Unix Original language –DEC PDP-7 assembly language First official version: 1971 –Design Do one thing well –Ran on DEC PDP-11 –No pipes or filters Added in version 2 Thompson and Ritchie: version 3 –New programming language (C language)

7 Understanding Operating Systems, Fifth Edition7 The Evolution of Unix (continued) AT&T forbidden to sell software –Universities and developers advanced software Commercial transformation Berkley BSD version: : government deregulation –AT&T personal computer with UNIX System 4 Contained additional Berkley version features AT&T System 4 promotion as standard fails 1990: two dozen versions

8 Understanding Operating Systems, Fifth Edition8 The Evolution of Unix (continued) 1991: AT&T UNIX system laboratories –Develops System V release 4 –Features System V release 3, BSD 4.3, SunOS, Xenix “The Open Group” formed –Owns UNIX trademark 1993: Berkeley –4.4 BSD: based on AT&T’s UNIX (AT&T license) –Novell acquires UNIX from AT&T

9 Understanding Operating Systems, Fifth Edition9 The Evolution of Unix (continued) Current releases –Modify “do one thing well” position –Commands more difficult to use Pipelines preserved –Adaptable to new situations with ease Meet new user needs –Full local area network support –Comply with international standards –Security improved –Uses Common Desktop Environment (CDE) –ISO/IEC 9945:2003 Standard

10 Understanding Operating Systems, Fifth Edition10 Design Goals Thompson and Ritchie vision –UNIX operating system Created by programmers for programmers –Fast, flexible, easy-to-use Immediate goals –Support software development Included utilities for customized code Utilities designed for simplicity: do one thing well Small manageable sections of code –Keep algorithms simple Based on simplicity, not sophistication

11 Understanding Operating Systems, Fifth Edition11 Design Goals (continued) Long-term goal –Portability Reduces conversion costs Application packages not obsolete –Achieved with UNIX version 4 Hardware independent POSIX –Portable operating system interface for computer environments IEEE standards defining portable operating system interface IEEE STD (2004 edition)

12 Understanding Operating Systems, Fifth Edition12 Memory Management Multiprogramming systems –Swapping (small jobs) Entire program in main memory before execution Program size restriction Round robin policy –Demand paging (large jobs) More complicated hardware Increases system overhead Thrashing (under heavy loads) Advantage: implements virtual memory concept

13 Understanding Operating Systems, Fifth Edition13 Memory Management (continued) Typical internal memory layout (single user) –Program code –Data segment –Stack

14 Understanding Operating Systems, Fifth Edition14 Memory Management (continued) Program code –Sharable portion of program –Reentrant code Physically shared by several processes Code protected: instructions not modified during normal execution Data references: without absolute physical address –Space allocation Program cannot release until all processes completed Text table: tracks processes using program code

15 Understanding Operating Systems, Fifth Edition15 Memory Management (continued) Data segment –After program code Grows toward higher memory locations –Nonsharable section of memory Stack –Starts at highest memory address Grows downward Subroutine calls and interrupts add information Main memory Process information saved when process interrupted –Nonsharable section of memory

16 Understanding Operating Systems, Fifth Edition16 Memory Management (continued) UNIX kernel –Implements “system calls” Memory boundaries for process coexistence –System calls File Manager interaction and request of I/O services –Implements most primitive system functions Permanently resides in memory –Uses LRU page replacement algorithm Network PCs, single-user, and multi-user systems –Use same memory management concepts

17 Understanding Operating Systems, Fifth Edition17 Process Management Handles –CPU allocation –Process scheduling –Satisfaction of process requests Kernel maintains tables –Coordinates process execution –Device allocation Uses predefined policies –Select process from READY queue –Begin execution Give time slice

18 Understanding Operating Systems, Fifth Edition18 Process Management (continued) Process scheduling algorithm –Selects highest priority process to run first –Priority value: accumulated CPU time Processes with large CPU time get lower priority –Compute-to-total-time ratio System updates for each job every second Total time process in system divided by used process CPU time –Ratio = one CPU-bound job

19 Understanding Operating Systems, Fifth Edition19 Process Management (continued) Process scheduling algorithm (continued) –Processes with same computed priority Handled by round robin –Interactive processes: low ratio (no special policies) –Balance I/O-bound jobs with CPU-bound jobs Keeps processor busy Minimizes waiting processes overhead

20 Understanding Operating Systems, Fifth Edition20 Process Management (continued) Process scheduling algorithm (continued) –Loading process from READY queue Process with longest secondary storage time –Swap out process Process waiting longest (disk I/O, idle ) –When processor becomes available Process selected may not be ready (waiting on I/O) Determine inactive but ready for execution Process priorities recalculated Handled dynamically

21 Understanding Operating Systems, Fifth Edition21 Process Table Versus User Table Simple processes (nonsharable code) Tables –Keep system running smoothly Process table –Always resides in memory –Maintains text table User table –Resides in memory while process is active –User table, process data segment, code segment Swapped as needed

22 Understanding Operating Systems, Fifth Edition22

23 Understanding Operating Systems, Fifth Edition23 Process Table Versus User Table (continued) Process table Each entry contains: –Process identification number –User identification number –Process memory address or secondary storage address –Process size and scheduling information Set up when process is created Deleted when process terminates

24 Understanding Operating Systems, Fifth Edition24 Process Table Versus User Table (continued) Text table –Sharable code processes –Process table maintains Contains: –Memory address or secondary storage address of text segment (sharable code) –Count: tracks number of processes using code Increased by one when process starts using code Decreased by one when process stops using code Count = 0: implies code no longer needed

25 Understanding Operating Systems, Fifth Edition25 Process Table Versus User Table (continued) User table –Allocated to each active process –Stored in transient memory area Contains: –User and group identification numbers Determine file access privileges –Pointers to system’s file table Every file process uses –Pointer to current directory –List of responses for various interrupts –All information accessible when process running

26 Understanding Operating Systems, Fifth Edition26 Synchronization UNIX –True multitasking operating system Requires processes wait for certain events –Each event represented by integers Equal to address of table associated with event Race occurs –Event happens during process transition decision Wait for event and entering WAIT state

27 Understanding Operating Systems, Fifth Edition27 Synchronization (continued) fork –Execute one program from another program –Second program Given all first program attributes (open files) –Save first program in original form –Split program: two copies Both run from statement after fork command –fork executed “Process id” (pid) generated Ensure each process has unique ID number

28 Understanding Operating Systems, Fifth Edition28 Synchronization (continued)

29 Understanding Operating Systems, Fifth Edition29 Synchronization (continued) wait –Synchronize process execution Suspend parent until child finished –Program IF-THEN-ELSE structure Controlled by pid value pid > zero: parent process pid = zero: child process pid < zero: error in fork call

30 Understanding Operating Systems, Fifth Edition30 Synchronization (continued)

31 Understanding Operating Systems, Fifth Edition31 Synchronization (continued) exec –Start new program execution from another program execl, execv, execls, execlp, and execvp –Successful exec call Overlay second program over first Only second program in memory –No return from successful exec call Parent-child concept: does not hold –Each exec call Followed by test ensuring successful completion

32 Understanding Operating Systems, Fifth Edition32 Synchronization (continued)

33 Understanding Operating Systems, Fifth Edition33 Device Management Device independence to applications –I/O device treated as special file type Device files given name –Descriptors called “iodes” Identifies devices, contains device information, stored in device directory Device drivers –Subroutines working with operating system –Supervise data transmission Between main memory and peripheral unit –Most common drivers included in UNIX

34 Understanding Operating Systems, Fifth Edition34 Device Management (continued) Device driver kernel incorporation –During system configuration Recent UNIX versions –Program called config –Automatically creates conf.c For any hardware configuration –conf.c contains parameters controlling resources Number of internal kernel buffers and swap space size –conf.c contains two tables bdevsw (“block I/O switch”) cdevsw (“character I/O switch”)

35 Understanding Operating Systems, Fifth Edition35 Device Classifications Divide I/O system –“Block I/O” system (“structured I/O” system) –“Character I/O” system (“unstructured I/O” system) Physical device identification –Minor device number –Major device number –Class: block or character

36 Understanding Operating Systems, Fifth Edition36 Device Classifications (continued)

37 Understanding Operating Systems, Fifth Edition37 Device Classifications (continued) Class: block or character –Each has configuration table Array of entry points into device drivers –Major device number Index to array to access appropriate code (specific driver) –Minor device number Passed as an argument to device driver Access one of several identical physical devices –Block I/O system Devices addressed as 512-byte block sequences Allows device manager to buffer (reduce I/O traffic)

38 Understanding Operating Systems, Fifth Edition38 Device Classifications (continued) Character class devices –Device drivers handle implementing character lists –Example: terminal Typical character device Two input queues and one output queue I/O procedure synchronized through hardware completion interrupts Some devices belong to both classes –Examples: disk drives, tape drives

39 Understanding Operating Systems, Fifth Edition39 Device Drivers Special section in kernel –Includes instructions Allows operating system communication with device Disk drive’s device drivers –Use seek strategy to minimize arm movement Kept in set of files –Loaded as needed Case of seldom used devices –Kept in memory all the time Loaded at boot time –Kept in /dev directory by default and convention

40 Understanding Operating Systems, Fifth Edition40 File Management Three file types –Directories –Ordinary files –Special files Each enjoys certain privileges Directories –Maintain hierarchical structure of file system –Users allowed to read information in directory files –Only system allowed directory file modification

41 Understanding Operating Systems, Fifth Edition41 File Management (continued) Ordinary files –Users store information –Protection based on user requests Related to read, write, execute, delete functions performed on file Special files –Device drivers providing I/O hardware interface –Appear as entries in directories –Part of file system (most in /dev directory) –Special filename indicates type of device association

42 Understanding Operating Systems, Fifth Edition42 File Management (continued) Files stored as sequences of bytes –No structure imposed Text files –Character strings Lines delimited by line feed, new line, character Binary files –Sequences of binary digits Grouped into words as they appear in memory during program execution Structure of files –Controlled by programs using them: not by system

43 Understanding Operating Systems, Fifth Edition43 File Management (continued) Organizes disk into blocks of 512 bytes each Divides disk into four basic regions –First region (address 0): reserved for booting –Second region: contains disk size and other regions’ boundaries –Third region includes: file definitions called “i-list” –Remaining region: free blocks available for file storage Files stored in contiguous empty blocks –Simple allocation and no need to compact

44 Understanding Operating Systems, Fifth Edition44 File Management (continued) “i-node” Each entry in i-list called an “i-node” (or inode) –Contains 13 disk addresses Contains specific file information –Owner’s identification –Protection bits, physical address, file size –Time of creation, last use, and last update –Number of links –File type Directory, ordinary file, or special file

45 Understanding Operating Systems, Fifth Edition45 File Naming Conventions Case-sensitive filenames 255 character length No file naming conventions –Some compilers expect specific suffixes Supports hierarchical tree file structure –Root directory identified by slash (/)

46 Understanding Operating Systems, Fifth Edition46 File Naming Conventions (continued)

47 Understanding Operating Systems, Fifth Edition47 File Naming Conventions (continued) Path name rules –Path name starting with slash Root directory –Path name One name or list of names: separated by slashes Last name on list: filename requested –Two periods (..) in path name Moves upward in hierarchy (closer to root) Only way to go up hierarchy All other path names go down tree –Spaces not allowed within path names

48 Understanding Operating Systems, Fifth Edition48 Directory Listings “long listing” –Eight pieces of information for each file First column –Shows file type and access privileges for each file First character: nature of file or directory Next three characters: access privileges granted file owner Next three characters: access privileges granted other user’s group members Last three characters: access privileges granted to users at large (system-wide)

49 Understanding Operating Systems, Fifth Edition49 Directory Listings (continued) Second column –Indicates number of links (number of aliases) Referring to same physical file Aliases –Important UNIX feature: support file sharing Several users work together on same project –Shared files appear in different directories belonging to different users –Filename: may be different from directory to directory –Eventually number will indicate when file no longer needed: can be deleted

50 Understanding Operating Systems, Fifth Edition50 Directory Listings (continued)

51 Understanding Operating Systems, Fifth Edition51 Data Structures File descriptors divided into parts –Hierarchical directories Contain filename and i-number Pointer to another location: i-node –i-node Contains rest of information –i-nodes stored in reserved part of device Where directory resides –i-node has 13 pointers (0–12)

52 Understanding Operating Systems, Fifth Edition52 Data Structures (continued)

53 Understanding Operating Systems, Fifth Edition53 Data Structures (continued) When file opened –Device, i-number, read/write pointer stored in system file table and indexed by i-node When file created –i-node allocated to it –Directory entry with filename and i-node number created

54 Understanding Operating Systems, Fifth Edition54 Data Structures (continued) When file linked –Directory entry created with new name –Original i-node number and link-count field in the i- node incremented by one When shared file deleted –Link-count field in i-node decremented by one –When count reaches zero Directory entry erased Deallocate all disk blocks and allocate i-node block to file

55 Understanding Operating Systems, Fifth Edition55 User Interface Command-driven system User commands –Very short One character or a group of characters (acronym) –Cannot be abbreviated or spelled out –Must be in correct case System prompt very economical –Only one character: ($) or (%) Error messages quite brief

56 Understanding Operating Systems, Fifth Edition56 User Interface (continued)

57 Understanding Operating Systems, Fifth Edition57 User Interface (continued) General syntax of commands –command arguments file_name “command” –Any legal operating system command Interpreted and executed by shell “arguments“ –Required for some commands, optional for others “file_name” –Relative or absolute path name

58 Understanding Operating Systems, Fifth Edition58 User Interface (continued)

59 Understanding Operating Systems, Fifth Edition59 Script Files Automate repetitious tasks –Command files Often called shell files or script files Each line of file –Valid instruction Executed by typing sh and script file name Also executed by defining file as executable command –Type filename at system prompt

60 Understanding Operating Systems, Fifth Edition60 Script Files (continued) Script file example setenv DBPATH /u/lumber:.:/zdlf/product/central/db setenv TERMCAP $INFODIR/etc/termcap stty erase `^H’ set savehistory set history=20 alias h history alias 4gen infogen -f setenv PATH /usr/info/bin:/etc

61 Understanding Operating Systems, Fifth Edition61 Redirection Send output to file or another device –Symbol: > (between command and destination) –Examples: ls > myfiles cat chapt1 chapt2 > sectiona, cat chapt* > sectiona –Symbol >> appends new file to an existing file –Examples: cat chapt1 chapt2 >> sectiona cat chapt* >> sectiona

62 Understanding Operating Systems, Fifth Edition62 Redirection (continued) Reverse redirection (<) –Takes input for program from existing file instead of keyboard –Example: mail ann roger < memo

63 Understanding Operating Systems, Fifth Edition63 Redirection (continued) Redirection (>) –Combined with system commands to achieve any desired results –Example: who > temporary Store in “temporary” file: all user names logged on Interpretation of –Carried out by shell –Not by individual program Input and output redirection –Used with any program

64 Understanding Operating Systems, Fifth Edition64 Pipes Provide possibility to redirect output or input to selected files or devices –Connect output from one program to input of another –No need for temporary or intermediate files –Example: who | sort Pipeline –Several programs simultaneously processing same I/O stream –Example: who | sort | lpr

65 Understanding Operating Systems, Fifth Edition65 Filters Program –Read some input, manipulate it, generate output –wc (word count): Example: wc journal System response: File journal has 10 lines, 140 words, 700 characters –sort: Contents of file sorted and displayed on screen Example: sort sortednames

66 Understanding Operating Systems, Fifth Edition66 Filters (continued) Sort list in alphabetical order ignoring letter case –sort –f > sortednames Obtain numerical sort in ascending order –sort -n > sortednums Obtain numerical sort in descending order –sort -nr > sortednums

67 Understanding Operating Systems, Fifth Edition67 Additional Commands man –Displays operating system online manual –Example: man cmp Displays page for compare (cmp) command grep –“global regular expression and print” –Look for specific character patterns –Examples: grep Pittsburgh maillist grep -v Pittsburgh maillist grep -c Pittsburgh maillist

68 Understanding Operating Systems, Fifth Edition68 Additional Commands (continued) grep (continued) –Can be combined with who command –Example: who | grep sam Sam’s name, device, date and time he logged in –Example: ls -l / | grep '^d‘ Displays subdirectories list (not files) in root directory nohup –Log off the system without program completion –Example: nohup cp oldlargefile newlargefile and

69 Understanding Operating Systems, Fifth Edition69 Additional Commands (continued) nice –Allows lowering program priority –Example: nice cp oldlargefile newlargefile and

70 Understanding Operating Systems, Fifth Edition70 Summary UNIX: major force in operating system field –Written by programmers for programmers –Quite popular among programmers Advantages –Spare user interface, device independence, portability, lack of verbosity, powerful command combinations Disadvantages –Learning command-driven interface, brief commands Graphical interface and point-and-click surfacing

Download ppt "Understanding Operating Systems Fifth Edition Chapter 13 Unix Operating System."

Similar presentations

Ads by Google