Chapter 15 UNIX and Linux Operating System s

78
Chapter 15 UNIX and Linux Operating Systems Understanding Operating Systems, Fourth Edition

description

Chapter 15 UNIX and Linux Operating System s. Understanding Operating Systems, Fourth Edition. 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 - PowerPoint PPT Presentation

Transcript of Chapter 15 UNIX and Linux Operating System s

Page 1: Chapter 15 UNIX and Linux  Operating System s

Chapter 15UNIX and Linux Operating

Systems

Understanding Operating Systems, Fourth Edition

Page 2: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 2

ObjectivesObjectives

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

Page 3: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 3

OverviewOverview

• 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

Page 4: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 4

OverviewOverview

• 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

Page 5: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 5

The Evolution of UNIXThe Evolution of UNIX

Table 15.1: Evolution of UNIX

Page 6: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 6

The Evolution of UNIXThe Evolution of UNIX (continued) (continued)

Table 15.1 (continued): Evolution of UNIX

Page 7: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 7

The Evolution of UNIX The Evolution of UNIX (continued)(continued)

Table 15.1 (continued): Evolution of UNIX

Page 8: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 8

The Evolution of UNIX The Evolution of UNIX (continued)(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 9945:2003 is big step

Page 9: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 9

The Evolution of LinuxThe 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

Page 10: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 10

The Evolution of Linux The Evolution of Linux (continued)(continued)

Table 15.2: Major releases of Linux by Red Hat, Inc.

Page 11: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 11

The Evolution of Linux The Evolution of Linux (continued)(continued)

Table 15.2 (continued): Major releases of Linux by Red Hat, Inc.

Page 12: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 12

The Evolution of Linux The Evolution of Linux (continued)(continued)

Table 15.2 (continued): Major releases of Linux by Red Hat, Inc.

Page 13: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 13

Design GoalsDesign 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

Page 14: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 14

Design Goals Design Goals (continued)(continued)

Table 15.3: System functions supported in Linux and UNIX

Page 15: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 15

Design Goals Design Goals (continued)(continued)

Table 15.3 (continued): System functions supported in Linux and UNIX

Page 16: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 16

UNIX Memory ManagementUNIX 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

Page 17: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 17

UNIX Memory Management UNIX Memory Management (continued)(continued)

Figure 15.1: Typical internal memory layout for single user-memory part UNIX

image

Page 18: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 18

UNIX Memory Management UNIX Memory Management (continued)(continued)

• Program code: – Sharable portion of program– Written in reentrant code as physically shared by

several processes – Protected so that its instructions aren’t modified in

any way during normal execution– Space allocated to program code can’t 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

Page 19: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 19

UNIX Memory Management UNIX Memory Management (continued)(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

Page 20: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 20

UNIX Memory Management UNIX Memory Management (continued)(continued)

• Unix Kernel:– Part of OS that implements “system calls” to set up

memory boundaries– Set of programs that implements most primitive of

that system’s 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

Page 21: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 21

Linux Memory ManagementLinux 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

Page 22: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 22

Linux Memory Management Linux Memory Management (continued)(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

Page 23: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 23

Linux Memory Management Linux Memory Management (continued)(continued)

• If any pages marked for deletion have been modified, they’re 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

Page 24: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 24

Processor ManagementProcessor 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

Page 25: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 25

Processor Management Processor Management (continued)(continued)

• If several processes have same computed priority, they’re 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

Page 26: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 26

Process Table Versus User TableProcess 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

Page 27: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 27

Process Table Versus User Table Process Table Versus User Table (continued)(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

Page 28: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 28

Process Table Versus User Table Process Table Versus User Table (continued)(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

Page 29: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 29

Process Table Versus User Table Process Table Versus User Table (continued)(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

Page 30: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 30

Process Table Versus User Table Process Table Versus User Table (continued)(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 system’s file table for every file being

used by the process– A pointer to current directory– A list of responses for various interrupts

Page 31: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 31

SynchronizationSynchronization

• 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 process’s transition between deciding to wait for event and entering WAIT state

Page 32: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 32

forkfork

• 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

Page 33: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 33

fork fork (continued)(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

Page 34: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 34

waitwait

• 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 > 0: parent process,

• pid = 0: child process

• pid < 0: error in fork call

Page 35: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 35

wait wait (continued)(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

Page 36: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 36

execexec

• 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 doesn’t hold here

– Each exec call is followed by test to ensure successful completion

Page 37: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 37

exec exec (continued)(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

Page 38: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 38

Linux Process ManagementLinux 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

Page 39: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 39

Linux Process Management Linux Process Management (continued)(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

Page 40: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 40

Organization of Table of ProcessesOrganization 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

Page 41: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 41

Process SynchronizationProcess 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

Page 42: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 42

Device ManagementDevice 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

Page 43: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 43

Device Management Device Management (continued)(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

Page 44: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 44

Device ClassificationsDevice 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 class—either block or character

• Each has a Configuration Table that contains an array of entry points into device drivers

Page 45: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 45

Device Classifications Device Classifications (continued)(continued)

Figure 15.6: The hierarchy of I/O devices in UNIX and Linux

Page 46: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 46

Device Classifications Device Classifications (continued)(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

Page 47: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 47

Device Classifications Device Classifications (continued)(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

Page 48: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 48

Device DriversDevice 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

Page 49: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 49

File ManagementFile 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

Page 50: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 50

File Management File Management (continued)(continued)

• Ordinary files: Files in which users store information– Protection is based on user’s 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 it’s associated

Page 51: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 51

File Management File Management (continued)(continued)

• UNIX stores files as sequences of bytes and doesn’t 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

Page 52: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 52

File Management File Management (continued)(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

Page 53: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 53

File Management File Management (continued)(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:– Owner’s 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

Page 54: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 54

Filenames in UNIX and LinuxFilenames 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 don’t 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 (/)

Page 55: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 55

Filenames in UNIX and Linux Filenames in UNIX and Linux (continued)(continued)

Figure 15.7: File hierarchy with ( / ) as root, directories as branches, and files as leaves

Page 56: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 56

Filenames in UNIX and Linux Filenames in UNIX and Linux (continued)(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

Page 57: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 57

Directories in UNIX and LinuxDirectories 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

Page 58: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 58

Directories in UNIX and Linux Directories in UNIX and Linux (continued)(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 user’s group– Last three characters describe access privileges

granted to users at large, those system-wide

Page 59: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 59

Directories in UNIX and Linux Directories in UNIX and Linux (continued)(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

Page 60: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 60

Data Structures in UNIXData 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 (0–12)

Page 61: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 61

Data Structures in UNIX Data Structures in UNIX (continued)(continued)

Figure 15.8: Hierarchy for directories, i-nodes, and file blocks

Page 62: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 62

Data Structures in UNIX Data Structures in UNIX (continued)(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

Page 63: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 63

Data Structures in UNIX Data Structures in UNIX (continued)(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

Page 64: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 64

User InterfaceUser 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) – Can’t 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

Page 65: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 65

User Interface User Interface (continued)(continued)

Table 15.5A: User commands

Page 66: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 66

User Interface User Interface (continued)(continued)

Table 15.5B: User commands

Page 67: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 67

User Interface User Interface (continued)(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

Page 68: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 68

Script FilesScript 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

Page 69: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 69

Script Files Script Files (continued)(continued)

• Example of a script file:

setenv DBPATH /u/lumber:.:/zdlf/product/central/dbsetenv TERMCAP $INFODIR/etc/termcapstty erase `^H’set savehistoryset history=20alias h historyalias 4gen infogen -fsetenv PATH /usr/info/bin:/etc

Page 70: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 70

RedirectionRedirection

• Used to send output to a file or to 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

• Reverse redirection (<) takes input for a program from an existing file instead of from keyboard– Example: mail ann roger < memo

Page 71: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 71

Redirection Redirection (continued)(continued)

• Redirection is combined with system commands to achieve any desired results:– Example: who > temporary (will store in file

named “temporary” the names of all users logged on to system)

• Interpretation of < and > is done by the shell and not by the individual program

• Input and output redirection can be used with any program

Page 72: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 72

PipesPipes

• 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

Page 73: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 73

FiltersFilters

• 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

Page 74: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 74

Filters Filters (continued)(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

Page 75: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 75

Additional CommandsAdditional 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

Page 76: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 76

Additional Commands Additional Commands (continued)(continued)

• grep can be combined with who command.– e.g., who | grep sam (displays Sam’s 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 &

Page 77: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 77

SummarySummary

• 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

Page 78: Chapter 15 UNIX and Linux  Operating System s

Understanding Operating Systems, Fourth Edition 78

Summary (continued)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