chapter 1 what is unix? “unix for programmers and users” third edition, prentice-hall, graham...

95
CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National University of Technology (Korea) and NYU Lecturer: Prof. Andrzej (AJ) Bieszczad Email: [email protected] Phone: 818-677-4954

Post on 22-Dec-2015

269 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

CHAPTER 1

What Is Unix?

“UNIX for Programmers and Users”Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES

Slides partially adapted from Kumoh National University of Technology (Korea) and NYU

Lecturer: Prof. Andrzej (AJ) BieszczadEmail: [email protected]

Phone: 818-677-4954

Page 2: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Computer Systems–Hardware –Operating System –Software –Communication

•UNIX Features–UNIX Philosophy –UNIX’s History

•CONTENTS

Page 3: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Operating Systems• Without its software, a computer is useless.

• With its software, a computer can store, process, and retrieve information, and engage in many other valuable activities.

• Computer software can be roughly divided into two kinds: 1. the system programs that manage the operation of the computer itself, 2. the application programs, which solve problems for their users.

1. The most fundamental of all the system program is operating system, which controls all the computer’s resources and provides the base upon which the application programs can be written.

2. Unix is a popular operating system. It is most commonly used in backend applications, on servers, powerful workstations, etc. One of the most well-designed operating systems of its time.

3. Linux and MacOS X (basically a BSD Unix) are popular desktop alternatives to MS Windows.

Page 4: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Operating Systems

•An operating system

–a program that controls the execution of application programs and acts as an interface between the user of a computer and the computer hardware.

•An operating system has four major components:

–process management,–input/output,–memory management, and–the file system.

• Having three objectives or performing three functions:

–convenience –efficiency–ability to evolve

Page 5: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Operating Systems

1. Convenience– An operating system makes a computer more convenient to use.

2. Efficiency– An operating system allows the computer system resources to be used in an efficient

manner.

3. Ability to evolve– An operating system should be constructed in such a way as to permit the effective

development, testing, and introduction of new system functions without at the same time interfering with service.

Page 6: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

Computer Hardware

Operating System

Utilities

Application Programs

End User ProgrammerOr Administrator

Operating SystemDesigner

• Layers and Views of a Computer System

Page 7: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Computer Systems

•A typical single-user computer system is built out of many parts, including:–a central processing unit( CPU ), –memory, –disks, –a monitor, and –a keyboard.

•Computer system is more than hardware. It consists of various hardware and software components. Computer hardware is useless without software.

•Computers can be connected together to form larger computer networks, enabling tasks to be distributed among individual computers.

Page 8: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

Banking System Airline Reservation Adventure games

Compilers Editors Command Interpreter

Operating System

Machine language

Microprogramming

Physical devices

Hardware

Systemprograms

Application programs

•Computer Systems

•A Computer System consists of hardware, system programs and application programs.

Page 9: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Computer Hardware

•Computer systems, whether large or small, multiuser or single user, expensive or cheap, include most of the following pieces of hardware:

•Central processing unit (CPU) –reads machine code (instructions in a form that a computer can understand) from

memory and executes it.

–A CPU is often thought of as the “brain” of a computer.

•Random-access memory (RAM)–holds machine code and data that are accessed by the CPU.

•Read-only memory (ROM) –holds both machine code and data.

–Its contents may not be changed and are remembered even when the power to the computer is turned off.

Page 10: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Computer Hardware

•Disk –holds large amount of data and code on a magnetic or optical medium and remembers it

all even when the power to the computer is turned off.

–Floppy disks are generally removable from the computer, whereas hard disks are not.

–Hard disks can hold a lot more information that floppy disks can.

•CD-ROM drive –allows digitally published information on a compact disk to be read by the computer.

•Monitor –displays information and comes in two types: monochrome and color.

Page 11: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Computer Hardware

•Graphics card –allows the CPU to display information on a monitor.

•Keyboard –allows a user to enter alphanumeric information.

•Mouse –allows a user easily to position cursors, icons, graphics, text, and other items on the

screen by using short movements of the hand.

•Printer –allows a user to obtain hard copies of information.

•Tape –generally used for making backup copies of information stored on disks.

Page 12: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Computer Hardware

•Modem –allows the user to communicate with other computers across a telephone line.

•Ethernet interface –allows computers to communicate at high speeds.

–Computers attach to an Ethernet by a special piece of hardware called an Ethernet interface.

•Other peripherals–many other kinds of peripherals that computer systems can support, including:

• graphics tablets, • optical scanners, • array processors, • sound cards, • voice recognition cards, • synthesizers, etc.

Page 13: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Operating Systems

•A computer system cannot function without an operating system.

•There are many different operating systems that are available for PCs, minicomputers, and mainframes;

•the most common ones are Windows, VMS, MacOS, and UNIX.

•MS Windows is only available for PCs•VMS is only available for mini-computers and mainframes, •and UNIX is available for virtually all platforms. programs

operating system

hardware

Page 14: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Unix System Structure

• Software is a collection of programs available in a computer system.

user

shell and utilities

kernel

hardware

c programsscripts

lsksh

gccfind

open()fork()exec()

Page 15: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Kernel

•Manage resources–Storage–Memory–CPU–Display–Network

•Sharing–Users–Tasks

•Communication

user

shell and utilities

kernel

hardware

Page 16: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Kernel Subsystems

•File system–Directory hierarchy, regular files, peripherals –Multiple file systems–Input/Output

• How processes access files, terminal I/O

•Process management–How processes share CPU, memory and signals–Scheduling–Interprocess Communication–Memory management

•UNIX variants have different implementations of different subsystems.

Page 17: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Kernel Subsystems

Page 18: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Kernel Interactions

•Processes accesses kernel facilities via system calls •Peripherals communicate with the kernel via hardware interrupts

Hardware Level

Kernel Level

User Level

System Calls

Interrupts

Page 19: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Talking to Kernel

Page 20: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Information about each process is stored in the kernel.

•Process table: contains an entry for every process in the system.

•Open-file table: contains at least one entry for every open file in the system.

•Kernel Data Structures

Code

Data

Code

Data

Code

Data

ProcessInfo

ProcessInfo

ProcessInfo

Open FileTable

ProcessTable

User Space

Kernel Space

Page 21: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Shell and Utilities

•The rest of the operating system

•Focus of this course

•Cause of debate in Linux community

user

shell and utilities

kernel

hardware

Page 22: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•UNIX Shell

•Shell is the user interface to the operating system

•Functionality:–Execute other programs–Manage files–Manage processes

•A program like any other•Executed when you log on

•How to use shells?

•Interactively–When you log in, you interactively use the shell

•Scripting–A set of shell commands that constitute an executable program: a script

Page 23: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Files and Processes

• A file is a collection of data that is usually stored on disk, although some files are stored on tape. • When a program is started, it is loaded from disk into RAM. When a program is

running, it is called a process. • Most processes read and write data from files.

Page 24: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Unix File System•Files are just sequences of bytes

–No file types (data vs. executable)–No sections–Example of UNIX philosophy (KISS: keep it simple…)•Directories are lists of files and other directories, along with their status:

–creation date–permissions, etc.•Each directory entry links to a file on the disk

–two different directory entries can link to the same file• in same directory or across different directories

–moving a file does not actually move any data around.• creates link in new location• deletes link in old location

•UNIX supports a hierarchical directory structure. •Files and processes have a “location” within the hierarchy of a directory. A process may change its own location and/or the location of a file.

•UNIX provides services for the creation, modification, and destruction of programs, processes, and files.

Page 25: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

/ (Root directory)

home bin

glass who sort

myfile.txt afile.txtsort

: a file

: a process

tim

•Unix File System

-a tiny UNIX directory hierarchy that contains four files and a process running the “sort” utility:

Page 26: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Two files in the same directory may not have the same name, although it’s perfectly OK for several files in different directories to have the same name. We need pathnames to differentiate between files with the same names located in different directories.•A pathname is a sequence of directory names that leads you through the hierarchy from a starting directory to a target file.

•For example, here’s a small hierarchy that contains three files called “myFile” in three separate directories.

myFile

myFile

• File Pathnames

/

binhome

timglass

myFile

Page 27: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•A pathname relative to the root directory is often termed an absolute, or full, pathname.

/home/glass/myFile /home/myFile /bin/myFile

• Absolute Pathnames

myFile

myFile

/

binhome

timglass

myFile

Page 28: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•A process may also unambiguously specify a file by using a pathname relative to its current working directory.

• UNIX file system supports the following special fields that may be used when supplying a relative pathname:

Field Meaning

. current directory

.. parent directory

• Absolute and Relative Pathnames

Page 29: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Relative Pathnames (from /home/glass)

myFile or ./myFile../myFile ../../bin/myFile

• Relative Pathnames

myFile

myFile

/

binhome

timglass

myFile

Page 30: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Disk Architecture

Page 31: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Storing a File

•Files are stored in multiple physical blocks on a disk.

Page 32: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Inodes

•File inode (index node) contains information about the whereabouts of the “pieces” of the file.

Page 33: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Logical Disk Layout

Page 34: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Directory Organization

Page 35: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Translating Pathnames into Inode Numbers

Page 36: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Symbolic Links

•Symbolic links are different than regular links (often called hard links).

•Can be thought of as a file that contains the name of another file

•Does not change link count for file–When original deleted, symbolic link remains

•They exist because:–Hard links don’t work across file systems–Hard links only work for regular files, not directories

direntfile

dirent

dirent filesymlink

Hard link

Symbolic Link

Page 37: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Unix Security

•Processes and files have an owner and may be protected against unauthorized access.

•A set of users can form a group. A user can be a member of multiple groups.

•A special user (id 0, name root) has complete control.

•Each user has a primary (default) group.

•This scheme is used to determine if file or process operations can be performed:–Can a given file be read? written to?–Can this program be run?–Can I use this piece of hardware?–Can I stop a particular process that’s running?

Page 38: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•File and Directory Permissions

•UNIX provides a way to protect files based on users and groups.

•Three types of permissions:–read, process may read contents of file–write, process may write contents of file–execute, process may execute file

•Three sets of permissions:–permissions for owner–permissions for group–permissions for other

•Same types and sets of permissions as for files apply to directories:–read: process may read the directory contents (i.e., list files)–write: process may add/remove files in the directory–execute: process may open files in directory or subdirectories

Page 39: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Devices as Special Files

•Besides files, input and output can go from/to various hardware devices.

•Unix Philosophy: Treat these devices as special files!

•Terminals, printers, and other devices are accessible in the same way as disk-based files.

home

bin usr

/

… dev

lpr tty modem

/dev/lpr /dev/tty /dev/modem

Page 40: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Mounting File Systems

•When UNIX is started, the directory hierarchy corresponds to the file system located on a single disk called the root device.

•Mounting allows root to splice the root directory of a file system into the existing directory hierarchy.

•File systems created on other devices can be attached to the original directory hierarchy using the mount mechanism.

Page 41: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Mounting File System

Device

/

/a/b

a

b

/

a

b

/

a

b

/

a

b

Mount table

root device external device

mountingpoint

Page 42: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Open File Table

•I/O operations are done on files by first opening them, ading/writing/etc., then closing them.

•The kernel maintains a global table containing information about each open file.

Inode Mode Count

1023 read 1

1331 read/write 2

Position

0

50

Page 43: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•The File Descriptor Table

•Each process has contains a table of files it has opened.•Each open file is associated with a number or handle, called file descriptor, (fd).•Each entry of this table points to an entry in the open file table.•Starts at 0

•Why not just file descriptor?

•Extra information stored:–Should the open file be inherited by children?

(close-on-exec flag)

•Convenient for kernel–indirection makes security easier

•Numbering scheme can be local to process (0 .. 128)

Page 44: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Stardard Input, Output and Error

•The first three entries in the file descriptor table are preset:–Entry 0 is for input–Entry 1 is for output–Entry 2 is for error messages

•By default all go to terminal (/dev/tty)

FileDescriptorTable

012

Page 45: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Processes•Program: collection of bytes stored in a file that can be run•Image: computer execution environment of program•Process: execution of an image

•Unix can execute many processes simultaneously.

•Process creation: interesting trait of UNIX•fork system call clones the current process

•exec system call replaces current process

•A fork is typically followed by an exec•All of the per process information is copied with the fork operation

–Working directory–Open files•Before exec, these values can be modified

A A A

A B

Page 46: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Processes

•Program arguments–When a process is started, it is sent a list of strings: argv, argc–The process can use this list however it wants to

•Ending a program–When a process ends, there is a return code associated with the process outcome–This is a non-negative integer

• 0 means success• anything larger than 0 represent various kinds of failure

–The return value is passed to the parent process

Page 47: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Organization of Executable File

Page 48: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Process Composition

• signal handling information• file descriptor table• CPU usage statistics

Page 49: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Process Lifecycle

Page 50: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Process GenealogyProcess generation

getty

initexecs

/bin/sh

loginexecs

gettyexecs

initexecs

getty

Initexecs

Init process 1forks init processes

Page 51: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Process Composition

•Process Information maintained by kernel

–Working directory–File descriptor table–Process id

• number used to identify process–Process group id

• number used to identify set of processes–Parent process id

• process id of the process that created the process–Effective user and group id

• The user and group this process is running with permissions of–Real user and group id

• The user and group that invoked the process–Umask

• Default file permissions for new file–Environment variables

Page 52: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Environment Variables•Environment of a Process

–A set of name-value pairs associated with a process–Keys and values are strings–Passed to children processes–Cannot be passed back up

•Environment Variables

•EDITOR–Tells the default editor to use•HISTSIZE

–Set by the shell program, usually bash.•HISTFILESIZE

–Set by the shell program, usually bash. The number of lines the user's $HOME/.bash_history file can contain as a maximum.

•HOME–A user's login directory.•HOSTNAME

–The network name of the host (this machine) set by the rc.sysinit script using either the /etc/HOSTNAME file or the /etc/sysconfig/network file. In modern versions of Redhat the file /etc/sysconfig/network is used.

•HOSTTYPE–Set by the kernel, and defines the architecture of the machine.

Page 53: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Environment Variables•LANG

–The name of a language to use.•LOGNAME

–The user's login name as set by the login program.•MAIL

–Set by the login program.•PAGER

–Used by the man command to specify the command to use to display man pages.Ex: PAGER=lessexport PAGER //exports it to the environment, Only need to use this once

•PATH–The directory prefixes used to search for programs and files. Set by the shell program, scripts, and

the user. This is set by login at startup, then may be modified by shell scripts.•PS1

–Defines the main shell prompt•PWD

–The current working directory. Set by the shell program such as bash.•SHELL

–The name of the user's login shell. Set by the login program.•TERM

–The terminal types for which output is to be prepared. Set by the getty program and preserved by the login program..

•USER–The user's name as set by the shell program.

Page 54: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Sharing CPU

•Operating-system function that UNIX provides is the sharing of limited resources among competing processes.

•Limited resources include:–CPUs, –memory, –disk space, and –peripherals such as printers

•UNIX shares CPUs among processes by dividing each second of CPU time into equal-size “slices” (typically 1/10 second)

•The slices are allocated to processes based on a priority scheme.

Page 55: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Processes Share CPU

Page 56: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Priority Queues

Page 57: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Scheduler

Page 58: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Sharing Memory

•UNIX shares memory among processes by dividing RAM up into thousands of equal-sized “pages” of memory.

•The pages are allocated to processes based on a priority scheme.

•UNIX shares disk space among users by dividing the disks into thousands of equal-sized “blocks”.

•The blocks are allocated to users based on a quota system.

•As we saw earlier, a single file is built out of one or more blocks.

•A special file, called a swap file, is used to cache memory pages of processes that are not executing at the moment.

Page 59: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Page Tables and Regions

Page 60: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Lading an Executable into Memory

Page 61: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Memory Management

Page 62: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Executing First Instruction

Page 63: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•After More Instructions

Page 64: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Swapping

Page 65: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Communication

•The components of a computer system cannot achieve very much when they work in isolation;

•For example:

A process may need to talk to a graphics card to display output. A process may need to talk to a keyboard to get input. A network mail system needs to talk to other computers to send and receive mail.

Two processes need to talk to each other in order to collaborate on a single problem.

•UNIX provides several different ways for processes and peripherals to talk to each other, depending on the type and the speed of the communication.

Page 66: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Communication•Processes can communicate using a number of means:

–passing arguments, environment–read/write regular files–exit values–inter-process communication with shared queues, memory and semaphores–signals–pipes–sockets

•A processes can send signal to another process if it has appropriate permissions.

•A pipe is a one-way medium-speed data channel that allows two processes on the same machine to talk.

•If the processes are on different machines connected by a network, then a mechanism called a “socket” may be used instead. A socket is a two-way high-speed data channel.

Page 67: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Signals

•The targeted process processes the signals according to it’s own rules:–explicitly ignore signal–specify action to be taken upon receipt (signal handler)–otherwise, default action takes place (usually process is killed)

Page 68: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Type of Signals

•Message type represented by a symbolic name.

•Some common signals:–SIGKILL kill process–SIGTERM – terminate–SIGINT – interrupt–SIGSTOP – stop–SIGCONT – continue–SIGSEGV – segmentation fault–SIGBUS – bus error

•When a child exits, it sends a SIGCHLD signal to its parent.

•If a parent wants to wait for a child to exit, it tells the system it wants to catch the SIGCHLD signal.

•When a parent does not issue a wait, it ignores the SIGCHLD signal.

Page 69: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Unix Pipes

•A special mechanism called a “pipe” built into the heart of UNIX to support cascading utilities.

•A pipe allows a user to specify that the output of one process is to be used as the input to another process.

•Two or more processes may be connected in this fashion, resulting in a “pipeline” of data flowing from the first process through to the last.

Page 70: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

Process 1 Process 2 Process 3

•Pipeline

•The nice thing about pipelines is that many problems can be solved by such an arrangement of processes.

•Each process in the pipeline performs a set of operations upon the data and then passes the results on to the next process for further processing.

Page 71: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Pipeline Example

•A utility called who that outputs an unsorted list of the users, and another utility called sort that outputs a sorted version of its input.

•These two utilities may be connected together with a pipe so that the output from who passes directly into sort, resulting in a sorted list of users.

who sort terminal

Page 72: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Pipes

•General idea: The input of one program is the output of the other, and vice versa

•Both programs run at the same time

•Often, only one end of the pipe is used

•Pipes chained together:–they are called filters

A B

A B

standard out

standard in

A B C

Page 73: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Pipe-Equivalent Communication Using a File

•Could we use a file instead of a pipe? YES.

•Run first program, save output into file•Run second program, using file as input

•Disadvantages:–Unnecessary use of the disk

• Slower• Can take up a lot of space

–Makes no use of multi-tasking

•Pipe is very similar, but does not involve the external device–all mechanisms stay in the realm of the operating system

process 1 process 2

Page 74: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Sockets

•Socket: a host-local, application-created, OS-controlled interface (a “door”) into which application process can both send and receive messages to/from another application process

•Socket API:–introduced in BSD4.1 UNIX, 1981–explicitly created, used, released by applications–client/server paradigm –two types of transport service via socket API:

• unreliable datagram (UDP)• reliable, byte stream-oriented (TCP)

Page 75: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

Client

Kernel

Server

Kernel

Client

Kernel

Network

Machine 1 Machine 2 Machine 3

Message from client to server

•Distributed Systems: The Client-Server Model

•In distributed processing the burden of computation is spread among many computers.

Page 76: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•The Socket Connection

Page 77: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Berkeley Socket Internals

- socket domain- socket protocol- a pointer to the socket’s mbuf lists- …

Page 78: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Socket-programming using TCP

•Socket: a door between application process and end-end-transport protocol (UCP or TCP)•TCP: reliable transfer of bytes from one process to another

process

TCP withbuffers,

variables

socket

controlled byapplicationdeveloper

controlled byoperating

system

host orserver

process

TCP withbuffers,

variables

socket

controlled byapplicationdeveloper

controlled byoperatingsystem

host orserver

internet

Page 79: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Unix Utilities

•Standard UNIX comes complete with at least 200 small utility programs, usually including:

–shells,–editors,–a C compiler,–matching with regular expressions,–searching,–a sorting utility,–software development tools,–text-processing tools, etc.

•There are Graphical User Interfaces to every Unix. Most of them are based on X Windows. The most popular are: CDE, Gnome, KDE. Apple’s popular Aqua is not based on X Windows.

•Popular packages like spreadsheets, compilers, and desktop-publishing tools are also commercially available.

Page 80: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Programmer Support•Unix is an “open” system, which means that the internal software architecture is well

documented and available in source-code form for a relatively small fee.

•Features of UNIX such as parallel processing, inter-process communication, and file handling are all easily accessible from a programming language such as C via a set of library routines known as system calls.

Page 81: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Unix Versions

•UNIX is a fairly standard operating system, with two main versions that are slowly merging into one.

•UNIX was created in Bell Laboratories and evolved from that into what is currently known as “System V” UNIX.

•The university of California at Berkeley obtained a copy of UNIX early on in its development and spawned another major version, known as BSD (Berkeley Standard Distribution) UNIX.

•UNIX international–AT&T, Sun Microsystems, --> System V Release 4.

•Open Software Foundation –IBM, Digital Equipment Corporation, Hewlett-Packard --> BSD UNIX, called OSF/1.

Page 82: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Unix Standards

•Both groups tried to comply with a set of standards set by the POSIX (Portable Operating System Interface) committee

•Most of the best features of BSD UNIX have been rolled into most System V-based versions of UNIX.

•UNIX is mostly written in the C language, which makes it relatively easy to port to different platforms.

•This feature is an important benefit and has contributed a great deal to the proliferation and success of UNIX.

Page 83: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Summary of Unix Features

•It allows many users to access a computer system at the same time. •It supports the creation, modification, and destruction of programs, processes and files. •It provides a directory hierarchy that gives a location to processes and files. •It shares CPUs, memory, and disk space in a fair and efficient manner between competing processes. •It allows processes and peripherals to talk to each other, even if they’re on different machines. •It comes complete with a large number of standard utilities. •There are plenty of high-quality, commercial software packages available for most versions. •It allows programmers to easily access operating features via a well-defined set of system calls, which are analogous to library routines. •It is a portable operating system and is thus available on a wide variety of platforms.

Page 84: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Unix Philosophy

•Small is beautiful–Easy to understand–Easy to maintain–More efficient–Better for reuse

•Make each program do one thing well–More complex functionality by combining programs–Make every program a filter–These small utilities should be combined to accomplish more complex tasks.

•Portability over efficiency–Most efficient implementation is rarely portable–Portability better for rapidly changing hardware

•Use flat ASCII files–Common, simple file format (yesterday’s XML)–Example of portability over efficiency

Page 85: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Unix Philosophy

•Reusable code–Good programmers write good code; great programmers borrow good code

•Build prototypes quickly (high level interpreted languages)

•Scripting increases leverage and portability–for example, the following line will list the logins of a system’s users on a single line

(ksh).

print $(who | awk '{print $1}' | sort | uniq) | sed 's/ /,/g'

who 755

awk 3,412

sort 2,614

uniq 302

sed 2,093 9,176 lines

Page 86: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Unix Philosophy

•Avoid captive interfaces–The user of a program isn’t always human–Look nice, but code is big and ugly–Problems with scale

•Silence is golden–Only report if something is wrong

•Think hierarchically

Page 87: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Unix Yesterday

•A computer scientist named Ken Thompson at Bell Laboratories built the first version of UNIX. It was built to support some gaming needs that could not be met by existing systems.

•written by using assembly language,

•only a single-user system,

•no network capability,

•poor memory-management system for sharing memory between processes.

•In spite of the shortcomings,--> efficient, compact, and fast, which was exactly what he wanted.

Page 88: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Unix Yesterday•A few years later, a colleague of Ken’s,

Dennis Ritchie, suggested that they rewrite UNIX using the C lanaguage.

•the UNIX system suddenly had a huge advantage over other operating systems - its source code was understandable.

•Only a small percentage of the original source code remained in assembly language, which meant the porting the operating system to a different machine was quite easy.

•AT&T, Bell Labs’ parent company, was not allowed to enter computer business, so Unix was not commercialized originally.

Page 89: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Unix Yesterday

•Bell Laboratories allowed universities to obtain a free copy of the UNIX source code.

•The University of California at Berkeley, made some huge improvements over the years, including the first good memory-management system and the first real networking capability.

•UC Berkeley offered a version of UNIX, called BSD (Berkeley Standard Distribution) to the general public.

Page 90: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Unix Today•The currently commercially available versions of UNIX include, but are not limited to,

offerings from AT&T, DEC, IBM, HP, Silicon Graphics, Inc., and Sun Microsystems.

•A more recent entry into the UNIX world is Linux, a free version of UNIX written by a student in Finland and now marketed and supported by several different companies.

•Embedded versions of UNIX are available for various hardware platforms.

•Apple abandoned old Mac OS for UNIX–Purchased NeXT in December 1996–Unveiled in 2000–Based on 4.4BSD-Lite–Aqua UI written over Darwin–Mac OS being phased out–Open Source

Page 91: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

FIGURE 1.6 An abbreviated genealogy of UNIX

UNIX

System V series

BSDseries

V.2

V.3

V.4

V.4.1

4.2

4.3

Sun OS(Solaris)

HP/UX

IBMAIX

OSF/1

Apollo

Page 92: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Unix Tomorrow

•UNIX will need to embrace some of the newer trends in computing, such as distributed and parallel processing and object-oriented programming.

–interesting work on Plan 9, Inferno – Lucent troubles slow down (kill?) the work

•Linux is a big player in the backend and on the desktop. Open Source community contributes great enhancements to the operating system, utilities and applications.

•Unix (Darwin) is clearly well built into Apple’s future.

Page 93: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Unix vs. Linux

Page 94: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Chapter Review

•In this chapter, we studied:–the main hardware components of a computer system –the purpose of an operating system –the meaning of the terms program, process, and file –the layout of a hierarchical directory structure –that UNIX shares CPUs, memory and disk space among competing processes –that UNIX supports communication between processes and peripherals –that UNIX comes complete with a multitude of standard utilities–that most major software packages are available on UNIX systems–that UNIX is an “open” system –that UNIX has a rosy future.

Page 95: CHAPTER 1 What Is Unix? “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National

What Is Unix?

•Quiz

1. What are the two main versions of UNIX, and how did each begin? 2. Write down five main functions of an operating system. 3. What is the difference between a process and a program? 4. What is the UNIX philosophy? 5. Who created UNIX? 6. What makes UNIX an “open” system?