Chapter 15 UNIX and Linux Operating Systems - PowerPoint PPT Presentation

1 / 78
About This Presentation
Title:

Chapter 15 UNIX and Linux Operating Systems

Description:

Successful exec call will overlay second program over first, leaving ... how the child process (Process 2) is overlaid by the ls program after the exec command ... – PowerPoint PPT presentation

Number of Views:428
Avg rating:3.0/5.0
Slides: 79
Provided by: unf
Category:

less

Transcript and Presenter's Notes

Title: Chapter 15 UNIX and Linux Operating Systems


1
Chapter 15UNIX and Linux Operating Systems
  • Understanding Operating Systems, Fourth Edition

2
Objectives
  • You should be able to describe
  • The similarities between UNIX and Linux
  • The design goals for both operating systems
  • The significance of using files to manipulate
    devices
  • The differences between command-driven and
    menu-driven interfaces
  • The roles of the Memory, Device, and Processor
    Managers

3
Overview
  • UNIX and Linux share three major advantages
  • Portable from large systems to small systems
  • Written in a high-level language, C
  • Powerful utilities
  • Brief, single-operation commands can be combined
    in a single command line to achieve any desired
    result
  • Device independent
  • Device drivers are included as part of the
    operating system, and not as part of devices

4
Overview
  • Disadvanatges
  • No single standardized version of operating
    system in UNIX
  • Both have very brief, cryptic commands
  • Novice users find unfriendly
  • Both UNIX and Linux are case-sensitive and
    strongly oriented toward lower-case characters

5
The Evolution of UNIX
Table 15.1 Evolution of UNIX
6
The Evolution of UNIX (continued)
Table 15.1 (continued) Evolution of UNIX
7
The Evolution of UNIX (continued)
Table 15.1 (continued) Evolution of UNIX
8
The Evolution of UNIX (continued)
  • New releases of UNIX include following features
  • Full support for local area networks
  • Complies with international operating system
    standards
  • Greatly improved system security
  • Meets many security requirements
  • Most feature Common Desktop Environment (CDE)
    which is a uniform GUI
  • Challenge To standardize to improve portability
    of programs from one system to another
  • Release of ISO/IEC 99452003 is big step

9
The Evolution of Linux
  • Linux is a contraction of Linus and UNIX
  • Based on a powerful multiplatform operating
    system, UNIX
  • Brought speed, efficiency, and flexibility of
    UNIX to PC environment
  • Linux is an open-source program
  • Has Windows-like graphical user interfaces

10
The Evolution of Linux (continued)
Table 15.2 Major releases of Linux by Red Hat,
Inc.
11
The Evolution of Linux (continued)
Table 15.2 (continued) Major releases of Linux
by Red Hat, Inc.
12
The Evolution of Linux (continued)
Table 15.2 (continued) Major releases of Linux
by Red Hat, Inc.
13
Design Goals
  • Linux and UNIX share similar design goals
  • Develop an operating system that would support
    software development
  • Included utilities in OS for which programmers
    typically need to write code
  • Each utility designed for simplicity
  • Each utility designed to be used in combination
    with each other
  • Keep its algorithms as simple as possible
  • Make it portable

14
Design Goals (continued)
Table 15.3 System functions supported in Linux
and UNIX
15
Design Goals (continued)
Table 15.3 (continued) System functions
supported in Linux and UNIX
16
UNIX Memory Management
  • Uses following memory management techniques
  • Swapping (for small jobs)
  • Demand paging (for large jobs)
  • Typical internal memory layout consists of
  • Program code
  • Data segment
  • Stack

17
UNIX Memory Management (continued)
Figure 15.1 Typical internal memory layout for
single user-memory part UNIX image
18
UNIX Memory Management (continued)
  • Program code
  • Sharable portion of program
  • Written in reentrant code as physically shared by
    several processes
  • Protected so that its instructions arent
    modified in any way during normal execution
  • Space allocated to program code cant be released
    until all processes using it have completed
    execution
  • UNIX uses text table to keep track of which
    processes are using which program code

19
UNIX Memory Management (continued)
  • Data Segment
  • Starts after program code and grows toward higher
    memory locations
  • Nonsharable section of memory
  • Stack
  • Starts at highest memory address and grows
    downward as subroutine calls and interrupts add
    information to it
  • Section of main memory where process information
    is saved when process is interrupted
  • Nonsharable section of memory

20
UNIX Memory Management (continued)
  • Unix Kernel
  • Part of OS that implements system calls to set
    up memory boundaries
  • Set of programs that implements most primitive of
    that systems functions
  • Permanently reside in memory
  • UNIX uses LRU page replacement algorithm
  • Same memory management concepts are used for
    network PCs, single-user and multi-user systems

21
Linux Memory Management
  • Allocates memory space to each process
  • e.g., In Intel X86, Linux allocates 1 GB of high
    order memory to kernel and 3 GB of memory to
    executing processes
  • Address space is divided among
  • Process code
  • Process data
  • Code and shared library data used by process
  • Stack used by process

22
Linux Memory Management (continued)
  • Linux has system calls that change size of
    process data segment as required
  • Offers memory protection based on type of
    information stored
  • When kernel needs memory space, pages are
    released using LRU algorithm
  • Maintains a dynamically managed area in memory, a
    page cache

23
Linux Memory Management (continued)
  • If any pages marked for deletion have been
    modified, theyre rewritten to disk
  • Page corresponding to file mapped into memory is
    rewritten to file
  • Page corresponding to data is saved on swap
    device
  • Linux uses system of page table to keep track of
    free and busy pages
  • Uses virtual memory mechanism

24
Processor Management
  • Processor Manager of UNIX system kernel handles
  • Allocation of CPU
  • Process scheduling
  • Satisfaction of process requests
  • Process scheduling algorithm picks process with
    highest priority to be run first
  • Any processes that have used a lot of CPU time
    will get lower priority than those that have not
  • System updates compute-to-total-time ratio for
    each job every second

25
Processor Management (continued)
  • If several processes have same computed priority,
    theyre handled round-robin
  • Process with longest time spent on secondary
    storage will be loaded first from READY queue
  • Process either waiting for disk I/O or currently
    idle is temporarily moved out to make room for
    new arrival
  • UNIX dynamically recalculates all process
    priorities to determine which inactive but ready
    process will begin execution when processor
    becomes available

26
Process Table Versus User Table
  • UNIX uses several tables to keep system running
    smoothly
  • Information on simple processes, those with
    nonsharable code, is stored in two sets of
    tables
  • Process table
  • Always resides in memory
  • User table
  • Resides in memory only while process is active
  • User table, together with process data segment
    and code segment, can be swapped into or out of
    main memory as needed

27
Process Table Versus User Table (continued)
Figure 15.2 Process control structure showing
how process table and text table interact for
processes with sharable code, as well as for
those without sharable code
28
Process Table Versus User Table (continued)
  • Process Table
  • Each entry contains following information
  • Process identification number
  • User identification number
  • Process memory address or secondary storage
    address
  • Size of process and scheduling information
  • Process table is set up when process is created
    and is deleted when process terminates

29
Process Table Versus User Table (continued)
  • Text Table
  • For processes with sharable code, process table
    maintains a text table, which contains
  • Memory address or secondary storage address of
    the text segment (sharable code)
  • A count to keep track of number of processes
    using this code
  • Increased by one when process starts using code
  • Decreased by one when process stops using code
  • Count 0 implies code is no longer needed

30
Process Table Versus User Table (continued)
  • User Table
  • Allocated to each active process
  • Kept in transient area of memory
  • Contains following information that must be
    accessible when process is running
  • User and group identification numbers to
    determine file access privileges
  • Pointers to systems file table for every file
    being used by the process
  • A pointer to current directory
  • A list of responses for various interrupts

31
Synchronization
  • UNIX is true multitasking operating system
  • Achieves process synchronization by requiring
    that processes wait for certain events
  • Each event is represented by integers equal to
    address of table associated with event
  • A race may occur if event happens during
    processs transition between deciding to wait for
    event and entering WAIT state

32
fork
  • fork Capability of executing one program from
    another program
  • Gives second program all attributes of first
    program, such as any open files, and saves first
    program in its original form
  • Splits program into two copies, which are both
    running from statement after fork command
  • When fork is executed process id (pid)
    generated
  • Ensures each process has own unique ID number

33
fork (continued)
Figure 15.3 When fork command is received,
parent process shown in (a) begets child
process shown in (b) and Statement 2 is
executed twice
34
wait
  • wait Allows programmer to synchronize process
    execution by suspending parent until child is
    finished
  • In a program, the IF-THEN-ELSE structure is
    controlled by value assigned to pid
  • pid gt 0 parent process,
  • pid 0 child process
  • pid lt 0 error in fork call

35
wait (continued)
Figure 15.4 wait command used in conjunction
with fork command synchronizes parent and child
processes. (a) shows parent process, (b) shows
parent and child after fork, and (c) shows parent
and child during wait
36
exec
  • exec Used to start execution of new program from
    another program, e.g., execl, execv, execls,
    execlp and execvp
  • Successful exec call will overlay second program
    over first, leaving only second program in memory
  • No return from successful exec call
  • Concept of parent-child doesnt hold here
  • Each exec call is followed by test to ensure
    successful completion

37
exec (continued)
Figure 15.5 exec command is used after fork and
wait combination. (a) shows parent before fork,
(b) shows parent and child after fork, and (c)
shows how the child process (Process 2) is
overlaid by the ls program after the exec command
38
Linux Process Management
  • Linux supports the concept of personality to
    allow processes coming from other operating
    systems to be executed
  • Each process is assigned to an execution domain
    specifying the way in which
  • System calls are carried out
  • Messages are sent to processes
  • Supports pipes to allow executing processes to
    exchange data
  • Has an extension, which permits process clones
    to be created

39
Linux Process Management (continued)
  • Clone process is created using primitive clone,
    by duplicating its parent process
  • Allows both processes to share same segment of
    code and data
  • Modification of one is visible to other, which is
    unlike classical processes
  • Ability to clone processes brings possibility of
    implementing servers in which several threads may
    be executing

40
Organization of Table of Processes
  • Each process is referenced by descriptor
  • Describes process attributes together with
    information needed to manage process
  • Kernel dynamically allocates these descriptors
    when processes begin execution
  • All process descriptors are organized in doubly
    linked list
  • Scheduler used Macro instructions to manage and
    update process descriptor lists as needed

41
Process Synchronization
  • To allow two processes to synchronize with each
    other, Linux provides
  • Wait queue Linked circular list of process
    descriptors
  • Semaphores Used to solve problems of mutual
    exclusion and problems of producers and consumers
  • In Linux they contain three fields
  • Semaphore counter
  • Number of waiting processes
  • List of processes waiting for semaphore

42
Device Management
  • UNIX and Linux are truly device independent
  • Both treat each I/O device as special type of
    file
  • Device files are given descriptors
  • Identify devices, contain information about them,
    and are stored in device directory
  • Device drivers
  • Written in C
  • Part of the kernel
  • Both come with device drivers to operate the most
    common peripheral devices

43
Device Management (continued)
  • Actual incorporation of device driver into kernel
    is done during system configuration
  • Recent versions of UNIX have program called
    config that automatically creates conf.c file for
    any given hardware configuration
  • Contains parameters that control resources such
    as number of internal buffer for kernel and size
    of swap space
  • Contains two tables
  • bdevsw (short for block I/O devices)
  • cdevsw (short for character I/O devices

44
Device Classifications
  • Both UNIX and Linux divide I/O system into
  • Block I/O system (structured I/O system)
  • Character I/O system (unstructured I/O
    system)
  • Each physical device is identified by
  • A minor device number
  • A major device number
  • A classeither block or character
  • Each has a Configuration Table that contains an
    array of entry points into device drivers

45
Device Classifications (continued)
Figure 15.6 The hierarchy of I/O devices in UNIX
and Linux
46
Device Classifications (continued)
  • Major device number Used as index to array to
    access appropriate code for specific device
    driver
  • Minor device number Passed to device driver as
    argument and is used to access one of several
    identical physical devices
  • Block I/O system Used for devices that can be
    addressed as sequence of 512-byte blocks
  • Allows Device Manager to use buffering to reduce
    I/O traffic

47
Device Classifications (continued)
  • Devices in character class are handled by device
    drivers that implement character lists
  • Example A terminal is typical character device
    that has two input queues and one output queue
  • I/O procedure is synchronized through hardware
    completion interrupts
  • Some devices can actually belong to both classes
    block and character
  • Example Disk drives and tape drives

48
Device Drivers
  • Special section in kernel, which includes all the
    instructions necessary for OS to communicate with
    device
  • Device drivers for disk drives use a seek
    strategy to minimize the arm movement
  • Kept in a set of files
  • Can be loaded as needed, in case of seldom used
    devices
  • Can be kept in memory all the time when operating
    system boots
  • Kept in /dev directory by default and convention

49
File Management
  • UNIX has three types of files and each file
    enjoys certain privileges
  • Directories
  • Ordinary files
  • Special files
  • Directories
  • Used by system to maintain hierarchical structure
    of file system
  • Users are allowed to read information in
    directory files
  • Only system is allowed to modify directory files

50
File Management (continued)
  • Ordinary files Files in which users store
    information
  • Protection is based on users requests
  • Related to read, write, execute, and delete
    functions that can be performed on a file
  • Special files Device drivers that provide
    interface to I/O hardware
  • Appear as entries in directories
  • Part of file system, and most of them reside in
    /dev directory
  • Name of each special file indicates type of
    device with which its associated

51
File Management (continued)
  • UNIX stores files as sequences of bytes and
    doesnt impose any structure on them
  • Text files are strings of characters with lines
    delimited by line feed, or new line, character
  • Binary files are sequences of binary digits
    grouped into words as they will appear in memory
    during program execution
  • Structure of files is controlled by programs that
    use them, not by system

52
File Management (continued)
  • UNIX file management system organizes disk into
    blocks of 512 bytes each
  • Divides disk into four basic regions
  • First region (address 0) reserved for booting
  • Second region contains size of disk and
    boundaries of other regions
  • Third region includes list of file definitions,
    i-list,
  • Remaining region holds free blocks available for
    file storage
  • Whenever possible files are stored in contiguous
    empty blocks

53
File Management (continued)
  • i-node
  • Each entry in the i-list is called an i-node
    (or inode) and contains 13 disk addresses
  • Each contains the following information on a
    specific file
  • Owners identification
  • Protection bits, physical address, file size
  • Time of creation, last use and last update
  • Number of links
  • If file is directory, ordinary file, or special
    file

54
Filenames in UNIX and Linux
  • Filenames are case sensitive
  • Linux and most versions of UNIX allow filenames
    to be of unlimited length
  • Older versions of UNIX have maximum of 14
    characters including any suffixes and period
  • OSs dont impose any naming conventions on files
  • Some compilers expect files to have specific
    suffixes
  • Linux and UNIX support hierarchical tree file
    structure
  • Root directory is identified by slash (/)

55
Filenames in UNIX and Linux (continued)
Figure 15.7 File hierarchy with ( / ) as root,
directories as branches, and files as
leaves
56
Filenames in UNIX and Linux (continued)
  • Rules that apply to all path names
  • If path name starts with slash, path starts at
    root directory
  • Path name can be either one name or list of names
    separated by slashes
  • Last name on list is name of file requested
  • Using two periods (..) in path name will move you
    upward in hierarchy (closer to root)
  • Only way to go up hierarchy all other path names
    go down tree
  • Spaces are not allowed within path names

57
Directories in UNIX and Linux
Table 15.4 List of files stored in the directory
journal from the system illustrated in Figure
15.7. The command ls -l (short for
listing-long) was used to generate this list
58
Directories in UNIX and Linux (continued)
  • long listing of files in a directory shows
    eight pieces of information for each file
  • First column shows the type of file and the
    access privileges for each file
  • First character describes nature of file or
    directory
  • Next three characters show access privileges
    granted to owner of file
  • Next three characters describe access privileges
    granted to other members of users group
  • Last three characters describe access privileges
    granted to users at large, those system-wide

59
Directories in UNIX and Linux (continued)
  • Second column in the directory listing indicates
    the number of links (number of aliases) that
    refer to the same physical file
  • Aliases are an important feature of UNIX
  • Support file sharing when several users work
    together on the same project
  • Make it convenient for the shared files to appear
    in different directories belonging to different
    users
  • Filename may be different from directory to
    directory
  • Eventually this number will indicate when the
    file is no longer needed and can be deleted

60
Data Structures in UNIX
  • UNIX divides the file descriptors into parts
  • Hierarchical directories containing only the name
    of the file and the i-number, which is a
    pointer to another location, the i-node,
  • i-node contains the rest of the information
  • All i-nodes are stored in a reserved part of the
    device where the directory resides
  • Each i-node has room for 13 pointers (012)

61
Data Structures in UNIX (continued)
Figure 15.8 Hierarchy for directories, i-nodes,
and file blocks
62
Data Structures in UNIX (continued)
  • When a file is opened
  • Its device, i-number, and read/write pointer are
    stored in the system file table and indexed by
    the i-node
  • When a file is created
  • An i-node is allocated to it
  • A directory entry with filename and its i-node
    number is created

63
Data Structures in UNIX (continued)
  • When a file is linked
  • A directory entry is created with the new name
  • Original i-node number, and the link-count field
    in the i-node is incremented by one
  • When a shared file is deleted
  • Link-count field in the i-node is decremented by
    one
  • When the count reaches zero, the directory entry
    is erased and all disk blocks allocated to the
    file, along with its i-node block, are deallocated

64
User Interface
  • UNIX and Linux are command-driven systems and
    many user commands are virtually identical
  • User commands
  • Are very short, either one character or a group
    of characters (acronym of words making command)
  • Cant be abbreviated or spelled out
  • Must be in the correct case
  • System prompt is very economical
  • Only one character, e.g., () or ()
  • Error messages are also quite brief

65
User Interface (continued)
Table 15.5A User commands
66
User Interface (continued)
Table 15.5B User commands
67
User Interface (continued)
  • General syntax of commands
  • command arguments file_name
  • command is any legal operating system command
  • interpreted and executed by the shell
  • arguments are required for some commands and
    optional for others
  • file_name can be a relative or absolute path
    name

68
Script Files
  • Command files, often called shell files or script
    files, can be used to automate repetitious tasks
  • Each line of the file is a valid instruction and
    can be executed by typing sh and name of script
    file
  • Can also be executed be defining the file as an
    executable command and typing filename at the
    system prompt
  • The default shell for Linux is called bash (for
    Bourne Again Shell)
  • Other common shells csh, and ksh

69
Script Files (continued)
  • Example of a script file
  • setenv DBPATH /u/lumber./zdlf/product/central/db
  • setenv TERMCAP INFODIR/etc/termcap
  • stty erase H
  • set savehistory
  • set history20
  • alias h history
  • alias 4gen infogen -f
  • setenv PATH /usr/info/bin/etc

70
Redirection
  • Used to send output to a file or to another
    device
  • Symbol gt (between command and destination)
  • Examples ls gt myfiles
  • cat chapt1 chapt2 gt sectiona
  • cat chapt gt sectiona
  • Symbol gtgt appends new file to an existing file
  • Examples cat chapt1 chapt2 gtgt sectiona
  • cat chapt gtgt sectiona
  • Reverse redirection (lt) takes input for a program
    from an existing file instead of from keyboard
  • Example mail ann roger lt memo

71
Redirection (continued)
  • Redirection is combined with system commands to
    achieve any desired results
  • Example who gt temporary (will store in file
    named temporary the names of all users logged
    on to system)
  • Interpretation of lt and gt is done by the shell
    and not by the individual program
  • Input and output redirection can be used with any
    program

72
Pipes
  • Pipes and filters make it possible to redirect
    output or input to selected files or devices
  • Pipe can connect output from one program to input
    of another without the need for temporary or
    intermediate files
  • Example who sort
  • A pipeline is several programs simultaneously
    processing the same I/O stream
  • Example who sort lpr

73
Filters
  • Programs that read some input, manipulate it in
    some way, and generate output
  • wc (word count) e.g., wc journal
  • System would respond with 10 140 700, meaning
    that the file journal has 10 lines, 140 words,
    and 700 characters
  • sort Contents of the file are sorted and
    displayed on the screen
  • Example sort sortednames

74
Filters (continued)
  • To sort the list in alphabetical order but ignore
    the case of letters
  • sort -f sortednames
  • To obtain a numerical sort in ascending order
  • sort -n sortednums
  • To obtain a numerical sort in descending order
  • sort -nr sortednums

75
Additional Commands
  • man displays online manual supplied with the
    operating system
  • man cmp (displays the page for the compare (cmp)
    command)
  • grep stands for global regular expression and
    print, looks for specific patterns of characters
  • Examples grep Pittsburgh maillist
  • grep -v Pittsburgh
    maillist
  • grep -c Pittsburgh
    maillist

76
Additional Commands (continued)
  • grep can be combined with who command.
  • e.g., who grep sam (displays Sams name,
    device, and the date and time he logged in)
  • ls -l / grep 'd (displays list of all
    subdirectories (but not the files) found in the
    root directory)
  • nohup Allows logging off the system without
    having to wait for program to finish
  • e.g., nohup cp oldlargefile newlargefile
  • nice Allows lowering the priority of a program
  • e.g., nice cp oldlargefile newlargefile

77
Summary
  • UNIX and Linux were written by programmers for
    programmers
  • Both are quite popular among those fluent in the
    ways of programming
  • Their advantages include spare user interface,
    device independence, portability, lack of
    verbosity, and powerful combinations of commands
  • Versions of UNIX can operate very large multiuser
    systems, single-user systems, and every size in
    between

78
Summary (continued)
  • Linux is being adopted widely for single-user and
    enterprise-wide computing systems
  • Linux is characterized by its power, flexibility,
    and constant maintenance
  • Linux applies all the features of UNIX, including
    multitasking and multiuser capabilities, to
    desktop computers
  • Both operating systems are expected to increase
    in use and popularity for many years to come
Write a Comment
User Comments (0)
About PowerShow.com