9781439079201_PPT_ch13

Download Report

Transcript 9781439079201_PPT_ch13

Understanding Operating Systems
Sixth Edition
Chapter 13
UNIX Operating System
Learning Objectives
•
•
•
•
•
After completing this chapter, you should be able to
describe:
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
Understanding Operating Systems, Sixth Edition
2
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
• Disadvantages
– No single standardized version
– Brief, cryptic commands difficult for novice learner
Understanding Operating Systems, Sixth Edition
3
History
• Research project originally in 1965
– Joint venture between Bell Labs, AT&T, General
Electric, and MIT
• Goal
– Develop MULTICS
• MULTICS ambition
– Serve diverse user group needs
• Too intricate, complex, large for commercial value
• Bell labs withdrew in 1969
Understanding Operating Systems, Sixth Edition
4
History (cont'd.)
Understanding Operating Systems, Sixth Edition
5
History (cont'd.)
Understanding Operating Systems, Sixth Edition
6
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)
Understanding Operating Systems, Sixth Edition
7
The Evolution of UNIX (cont'd.)
• AT&T forbidden to sell software
– Universities and developers advanced software
• Commercial transformation
• Berkley BSD version: 1973-1975
• 1984: 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
Understanding Operating Systems, Sixth Edition
8
The Evolution of UNIX (cont'd.)
• 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
Understanding Operating Systems, Sixth Edition
9
The Evolution of UNIX (cont'd.)
• 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
Understanding Operating Systems, Sixth Edition
10
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
Understanding Operating Systems, Sixth Edition
11
Design Goals (cont'd.)
• 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. 1003.1 (2004 edition)
Understanding Operating Systems, Sixth Edition
12
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
Understanding Operating Systems, Sixth Edition
13
Memory Management (cont'd.)
• Typical internal memory layout (single user)
– Program code
– Data segment
– Stack
Understanding Operating Systems, Sixth Edition
14
Memory Management (cont'd.)
• 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
Understanding Operating Systems, Sixth Edition
15
Memory Management (cont'd.)
• 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
Understanding Operating Systems, Sixth Edition
16
16
Memory Management (cont'd.)
• 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
Understanding Operating Systems, Sixth Edition
17
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
Understanding Operating Systems, Sixth Edition
18
Process Management (cont'd.)
• 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
Understanding Operating Systems, Sixth Edition
19
Process Management (cont'd.)
• Process scheduling algorithm (cont'd.)
– 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
Understanding Operating Systems, Sixth Edition
20
Process Management (cont'd.)
• Process scheduling algorithm (cont'd.)
– 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
Understanding Operating Systems, Sixth Edition
21
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
Understanding Operating Systems, Sixth Edition
22
Process Table Versus User Table (cont'd.)
• 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
Understanding Operating Systems, Sixth Edition
23
Process Table Versus User Table (cont'd.)
• 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
Understanding Operating Systems, Sixth Edition
24
Process Table Versus User Table (cont'd.)
• 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
Understanding Operating Systems, Sixth Edition
25
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
Understanding Operating Systems, Sixth Edition
26
Synchronization (cont'd.)
• 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
Understanding Operating Systems, Sixth Edition
27
Synchronization (cont'd.)
Understanding Operating Systems, Sixth Edition
28
Synchronization (cont'd.)
• 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
Understanding Operating Systems, Sixth Edition
29
Synchronization (cont'd.)
Understanding Operating Systems, Sixth Edition
30
Synchronization (cont'd.)
• 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
Understanding Operating Systems, Sixth Edition
31
Synchronization (cont'd.)
Understanding Operating Systems, Sixth Edition
32
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
Understanding Operating Systems, Sixth Edition
33
Device Management (cont'd.)
• 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”)
Understanding Operating Systems, Sixth Edition
34
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
Understanding Operating Systems, Sixth Edition
35
Device Classifications (cont'd.)
Understanding Operating Systems, Sixth Edition
36
Device Classifications (cont'd.)
• 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)
Understanding Operating Systems, Sixth Edition
37
Device Classifications (cont'd.)
• 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
Understanding Operating Systems, Sixth Edition
38
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
Understanding Operating Systems, Sixth Edition
39
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
Understanding Operating Systems, Sixth Edition
40
File Management (cont'd.)
• 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
Understanding Operating Systems, Sixth Edition
41
File Management (cont'd.)
• 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
Understanding Operating Systems, Sixth Edition
42
File Management (cont'd.)
• 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
Understanding Operating Systems, Sixth Edition
43
File Management (cont'd.)
• “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
Understanding Operating Systems, Sixth Edition
44
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 (/)
Understanding Operating Systems, Sixth Edition
45
File Naming Conventions (cont'd.)
Understanding Operating Systems, Sixth Edition
46
File Naming Conventions (cont'd.)
• 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
Understanding Operating Systems, Sixth Edition
47
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)
Understanding Operating Systems, Sixth Edition
48
Directory Listings (cont'd.)
• 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
Understanding Operating Systems, Sixth Edition
49
Directory Listings (cont'd.)
Understanding Operating Systems, Sixth Edition
50
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)
Understanding Operating Systems, Sixth Edition
51
Data Structures (cont'd.)
Understanding Operating Systems, Sixth Edition
52
Data Structures (cont'd.)
• 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
Understanding Operating Systems, Sixth Edition
53
Data Structures (cont'd.)
• When file linked
– Directory entry created with new name
– Original i-node number and link-count field in the inode 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
Understanding Operating Systems, Sixth Edition
54
User Command 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
Understanding Operating Systems, Sixth Edition
55
User Command Interface (cont'd.)
Understanding Operating Systems, Sixth Edition
56
User Command Interface (cont'd.)
• 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
Understanding Operating Systems, Sixth Edition
57
User Interface (cont'd.)
Understanding Operating Systems, Sixth Edition
58
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
Understanding Operating Systems, Sixth Edition
59
Script Files (cont'd.)
• 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
Understanding Operating Systems, Sixth Edition
60
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
Understanding Operating Systems, Sixth Edition
61
Redirection (cont'd.)
• Reverse redirection (<)
– Takes input for program from existing file instead of
keyboard
– Example:
• mail ann roger < memo
Understanding Operating Systems, Sixth Edition
62
Redirection (cont'd.)
• Redirection (>)
– Combined with system commands to achieve any
desired results
– Example: who > temporary
• Store in “temporary” file: all user names logged on
• Interpretation of < and >
– Carried out by shell
– Not by individual program
• Input and output redirection
– Used with any program
Understanding Operating Systems, Sixth Edition
63
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
Understanding Operating Systems, Sixth Edition
64
Filters
• Program
– Read some input, manipulate it, generate output
– wc (word count):
• Example: wc journal
• System response: 10 140 700
• File journal has 10 lines, 140 words, 700 characters
– sort: Contents of file sorted and displayed on screen
• Example: sort sortednames
Understanding Operating Systems, Sixth Edition
65
Filters (cont'd.)
• 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
Understanding Operating Systems, Sixth Edition
66
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
Understanding Operating Systems, Sixth Edition
67
Additional Commands (cont'd.)
• grep (cont'd.)
– 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
Understanding Operating Systems, Sixth Edition
68
Additional Commands (cont'd.)
• nice
– Allows lowering program priority
– Example:
nice cp oldlargefile newlargefile and
Understanding Operating Systems, Sixth Edition
69
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
Understanding Operating Systems, Sixth Edition
70