2.26k likes | 2.55k Vues
The UNIX Operating System. UNIX Operating System. Objectives : Learn about the Unix Operating System and develop the skills required to build software applications in the Unix Environment. Contents :. 1. Introduction & History of UNIX 2. File System 3. Basic Utilities
E N D
UNIX Operating System Objectives : Learn about the Unix Operating System and develop the skills required to build software applications in the Unix Environment.
Contents : 1. Introduction & History of UNIX 2. File System 3. Basic Utilities 4. Shell Features 5. Advanced Utilities 6. Communication Features 7. System Calls
Chapter 1 Introduction and History of UNIX
Introduction and History of UNIX • 1. Evolution • 2. Development • 3. Standard release- AT&T versions • 4. BSD UNIX • 5. Other implementations of UNIX • 6. Features of UNIX • 7. UNIX Philosophy • 8. UNIX operating system • 9. UNIX Kernel • 10. Programming Environment • 11. Design Principles • 12. Limitations
Evolution • Primarily influenced by MULTICS • MULTICS • - Developed for GENERAL ELECTRIC 645 • mainframe computer • - Interactive operating system • - Batch - mode characteristics • UNIX Operating System - First Version developed in 1969 by • Ken Thompson on DEC PDP Series ( PDP - 7 ) • - Business, Scientific and Industrial Users
Development • * Originally written in assembly language for PDP-7 • * Transportability facilitated by Thompson who developed the B language • * B language modified by Ritchie and renamed as C language • * Thompson (1980) and others wrote UNIX in C which could be ported to any computer
Standard release - AT&T Versions • Version 3 • Written in C • • Moved to PDP - 11/45 and • PDP - 11/70 • Version 6 • Released in 1975 • • For use by universities only • Version 7 • Released in 1978 • • First commercial version but primarly used in universities • • 32V - VAX version • Version 8 • UNIX Support Group(USG) takes responsibility • • Research Group still busy
Standard release - AT&T Versions …Contd... • System III • Released in 1981 • • Commercial orientation • • Over 100 manufacturers of UNIX-based • micro , mini and mainframes • • UNIX users > 100,000 • System V • Release 1 • Released in 1983 • • Enhancement of System III • System V • Release 2 • Released in 1984 • • Enhancements of System V , Release 1 • System V • Release 3 • Released in 1988 • System V • Release 4.0 •
BSD UNIX (from Berkeley Software Distributions) * UNIX's entry into University of California, Berkeley Campus during 1976-77 * Inputs of UCB Faculty/researchers incorporated in System V of AT&T UNIX UNIX 3BSD • Released in 1978 • Developed by Bill Joy and Ozalp Baboglu • Added Virtual memory, Demand paging to the VAX version 32V UNIX 4BSD • DARPA - funded Development • Provided support for DARPA TCP/IP • C-Shell , ex/vi , new compilers for PASCAL and LISP were added UNIX 4.1 BSD • Released in 1981 UNIX 4.2 BSD • Released in 1983 UNIX 4.3 BSD • Latest Release
Other Implementations of UNIX (based on Version 7, System III, System V of AT&T UNIX or UNIX 4.2 BSD) Xenix Microsoft’s UNIX operating system to run on microcomputers IBM PC/IX IBM PC Zeus Zilog Computers DEC Ultrix DEC HP-UX HP UNIX SUN Elxsi UNIX ELXSI Pyramid UNIX Pyramid Data General UNIX Data General Perkin Elmer UNIX Perkin Elmer MassComp UNIX Mass Computers NBI UNIX NBI Amdahl UNIX Amdahl
UNIX Features • Multitasking Performing tasks simultaneously rather than sequentially • e.g., While printing a document , start editing another document • Each task is considered to be a process • Multi-user Several users can use the same computer simultaneously • i.e , more than one keyboard and terminal • can be connected to one computer • Highly cost-effective • Portability Easier to modify the UNIX system code for installation on a new computer rather • than write from scratch a new operating system
UNIX Features UNIX System supplied tools Integral utilities Basic Operation of Operating system like Command interpreter or Shell Tools Text print formatting like nroff and typesetting troff
* Available on micros, minis and mainframes • * UNIX Communication and electronic mail • • Communication between different terminals hooked to same computer • • Communication between computers of different • sizes and types in different locations as far away • as other countries • * Incorporation of third party application programs • * Hierarchical File System • * On-Line Help facility • Example : man <Command> • * Library of application software
The UNIX Philosophy • Make each program do one thing well • Expect the output of one program to become the input to another • Suited for prototype development i.e., design and build easily • Modular approach i.e., be prepared to throw and rebuild • Usage of tools • Building essential tools
The UNIX Operating System Kernel Schedules tasks and manages data storage Shell A program that • interprets the user commands/requests • calls programs from memory and • executes them one at a time or in a series (called a pipe) Tools & Specific capabilities added on to the OS Applications Kernel( Heart of Unix Operating System) Shell Interpreter Tools and Applications
The Users • Shells and Commands • Compilers and Interpreters • System Libraries • System Call Interface to Kernel • Signal File System CPU Scheduling • Terminal Swapping Page • Handling Replacement • Character Block Demand Paging • I/O System I/O System • Terminal Disk & Tape Virtual • Drivers Drivers Memory • Kernel Interface to the Hardware • Terminal Device Memory • Controller Controller Controller • Terminals Disks & Tapes Physical • Memory
File Management And Security Networking Services Input / Output Services Date and Time Services Process Scheduling Signal Handling System Administration and Accounting Memory Management The UNIX Kernel UNIX SYSTEM KERNEL
The Programming Environment * A GOOD operating system !! • Simple yet powerful • Allows building of tools, writing of small programs and putting them together • A rich & productive environment * A PORTABLE operating system !! • Written in C • Runs on a range of computers • Source code is available
The Design Principles • * Designed for Programmers • * Interactive • * Multiple Processes can be initiated • Foreground Process • Background Process • * Methods to Co-ordinate Process • * Signal to communicate with processes • * Files, Directories, Devices treated as files • * Tree structured directories to hold files • * Emphasis on program development facilities • * Sources available on-line • * Simplicity before efficiency
Drawbacks of UNIX • * Designed for computer professionals • * Not a real-time operating system • * File Security depends on owner • * Defective programs may keep running
Chapter 2 File System
The UNIX File System • 1. File System Layout • 2. Concepts of file • 3. Features of File system • 4. Starting and Ending a session • 5. File Management utilities • 6. Directory Management • 7. File operation • 8. Mountable File System • 9. File security
File Systems in UNIX • Disks are partitioned into File Systems. • - Logical blocks of 512 bytes or multiples • - Arranged to form a hierarchical structure • - Convenient to manage data • File System Layout • Boot Super Inode Data • block block list block • Boot block • - generally occupies the first sector • - may contain bootstrap code • Super block • - Information about the file system • How large, where free and other details • Inode list • - Contains a list of inodes • - One inode is the root inode • Data block • - Contains file and administrative data • - Allocated data can belong to that block • only
Classification of files in UNIX • - Ordinary Files • - Directory Files • - Special Files • - Standard Files
Concept of Ordinary Files * A File in UNIX is a Stream of bytes ( 8-bits) Kernel does not impose a structure on files * File may contain text, data and even machine language code Examples Text Files : Lines of ASCII characters separated by a new-line Commands : Sequence of commands interpreted by UNIX text Data : File containing data as stream of bytes Executable : File containing machine language instructions * The files format remains unchanged but only the way the program interprets it is different
Concept of Directory Files • * Gathering together related files in a common place • * Every file is assigned to a Directory • * Directories have names (maximum of 14 characters) • * A file within a Directory can itself be another Directory (A Sub-directory) • * Internally a Directory is just a file that contains • - a list of file names • - their Inode Numbers and • - a pointer to the actual file on the disk • * An upper limit of around 35 sub -directories • Examples • / ( Forward slash ) Prime or Root Directory • Note - in DOS it is \ ( Backward slash ) • /usr Directory for the user • /usr/trg1 Sub-Directory for trg1 under Directory usr
Concept of Special Files • * Used to reference Physical devices such as terminals, disks, floppy drives and tape drives • * Read and written like ordinary files • * Requests cause activation of the associated Physical Device • * Device Drivers associated with each file • * Types : • Character file Terminal (tty0, tty1 ) Transmits data Character by • Character • Block file Disk Drives (hd0,fd0) Transmits data in 512 or 1024 • byte chunks • * Major and Minor numbers identify the hardware link • Major No.s : Indicates type of device • Minor No.s : Different instances of the device
Concept of Standard Files • * Helps display information on the screen • * Special Names for Communication channels • * Keyboard input channel is called Standard input • (stdin) - file id is 0 • * Terminal Screen output is called Standard output • (stdout) - file id is 1 • Diagnostic error messages (generated by a program) are sent to Standard error • (stderr) - file id is 2 ( shown on terminal screen ) • * All three files are open by default at the time of login
File Names * A means for the system to identify a file Note : Unix is case sensitive * User accesses a file by a user-assigned file name * Can be a sequence of characters (a maximum of 14 ) * May be identified by two or more names (Multiple links to a file) * Internally assigned a unique inode number (for a File System) * Different files can be grouped under a directory
Path Names Absolute Path name * A file is identified by the path name from the root e.g., /usr/trg/c/test.c where • test.c is an ordinary file • usr, trg, c are directories • trg is a sub-directory under usr Relative path name * UNIX keeps track of the user's current directory * If a "/" does not precede a file name then the name interpretation begins with the current directory e.g., If current directory is /usr/trg then the file could be just referenced as c/test.c
Features • * Hierarchical • * Security on each file • - Owner • - Group • - All others • * Separate security for • - read • - write and • - execute • * Removable • * File Independence - • * Time stamp on each file • - Modification time • - Access time
spell Unix bin troff console --- dev lp0 src tty0 man sh uch bin --- csh bin --- local lib Libc.a lib --- --- / usr include *.h spool tmac lib troff passwd etc group --- init tmp --- tmp ---
Standard File Hierarchy • /bin Basic Unix utilities cp, mv, ln • /dev Special I/O device files fd0, lp0 • /etc Administrative Programs passwd, shutdown • /lib Libraries used by Unix libc.a • /usr/bin Unix utilities cal, bc,spell • /usr/adm Administrative commands • and files adduser • /tmp Temporary files created • on error conditions
/usr/games - Game Programs • /usr/include - Include files for language procedure • Examples : C-header files • stdio.h, math.h • /usr/lib - Archive libraries • Example : troff • /usr/mail - Mail files • Example : mailbox • /usr/news - News files • /usr/spool - Spool files • /usr/tmp - Temporary files • /usr/src -Program Source Files
Security and Access Methods • * Three levels of access • User/Owner, group, others • * Three types of access on Files and Directories • Read, Write, Execute • Access Mode Ordinary Directory • Read Examination of Listing of • File Contents files within Directory • Write Allows changing Creating new • of file contents files within Directory • Execute Executing file as Searching the • a command Directory allowed allowed
Starting and Ending a Session • login : User can type his name and password to identify himself • login command can be used as • $ exec login • to log-on onto another user account after identifying yourself in response to prompts for user name and password • su setuser • This is used to become another user or super-user provided the password is known. • e.g., $su • Prompt the user for the superuser password $su - trg2 • Prompt the user for the password of user trg2 $su - trg2 -c "ls -l" • Temporarily changes to trg2 and executes the command ls -l and • comes back to the original user
Starting And Ending A Session …Contd…. • passwdChange the password for the user • e.g., $ passwd • Prompt you for old password and new password • logout This command exits or logs-out from the current user • and executes the file .logout before coming out • e.g., $ logout • or • $ exit • or • $ <ctrl-d> • exits from the current login
File Management Utilities • Directory Operation File Comp. Security • Management • cd cmp passwd • pwd comm crypt • mkdir chown • rmdir chgrp • mvdir umask • chmod • File File Mountable Copy, Move • contents compression file Remove & Time • cat pack mount cp • ls unpack umount ln • wc mv • file rm • touch
mkdir creates a new directory • rm removes a file • rmdir removes a directory • du displays disk usage • df displays number of free block • touch updates the time of last modification • find locates files that match certain area • file displays the type of file • pwd displays full pathname of current directory
Command Structure General Structure: Command Name [Options] [Arguments] E.g., Command Name Tells the shell what to do (in this case list files) Options Control how the command will work (in this case ask for a long listing) Arguments on which the command works (in this case the directory usr/trg ) -l ls /usr/trg
Directory Management cd Change working Directory cd.. Parent Directory cd. Current Directory e.g., $ cd /usr/trg/c ( current Directory is c ) $ cd .. ( current Directory is trg ) $ cd ./c ( current Directory is again c ) or $ cd c $ cd ( home directory - in this case /usr/trg) mkdirMake a Directory $ mkdir pathname Makes Directory in 777 mode Write permission should at least be permitted for owner in parent Directory e.g., $ mkdir /usr/trg2 ( makes directory trg2 )
rmdir Remove a Directory • $ rmdir pathname • * Directory should be empty, or else • rm -r (recursively remove) • e.g., • $ rmdir /usr/trg2 (removes directory trg2) • pwd Print Working Directory
File Contents • cat Concatenate & Print on screen or printer • $cat [Options] [Arguments] • Options - take input from stdin -n no. of output lines • -s squeeze adj. blank lines • -v enable display of non-printing characters • -b used with -n to avoid numbering blank lines • e.g., • $ cat try.c Display the contents of try.c on the screen • $ cat Takes input from stdin i.e. keyboard and displays on screen
$ cat f1 > f2 Takes input from file f1 & puts it • on file f2 • $ cat f2 > f3f3 contains the contents of f1 • $ cat f4 >> f3 Appends the contents of f4 to • file f3 • $ cat try[0-3] > final The file final contains contents of try0, try1, try2 try3 • $ cat test* > report The file report contains all files beginning with test
Is[Options]List the Directory Contents • Options -1 number one single column output • -l long format (II also used) • -a all entries including dot files • -s gives no. of disk blocks • -i inode no. • -t ordered by modification time recent • first recursively display all directories, • starting specified or current directory
$ Is -I List the files along with the protection bits and the user • $ Is -a List the files starting with .and..also • $ Is -1 symtab.c • symtab.o • treegen • test • $ Is -I -rw-r—r— 1 smj proj1 30766 Mar 3 15:08 symtab.c • -rw-r—r— 1 smj proj1 8759 Mar 3 15:12 symtab.o • -rwxr-xr-x 4 smj proj1 40743 Mar 3 15:23 treegen • drwxrwxr-x 1 smj proj1 53 Mar 1 09:15 test • $ Is -a . • .. • .profile • .cshrc • symtab.c • ... • $ Is -iI 10936-rw-r—r—I smj proj1 3076 Mar 3 15:08 test.c • 10936 - inode number of file test.c
wc Word Count • $wc [Options] filename • Options - Display no. of lines, words, characters • -I Display no. of lines • -w Display no. of words • -c Display no. of characters • e.g., $ wc test.c • 20 200 5678 • 20 - lines • 200 - words • 5678- characters • nl no. of lines in the file and temp’ly lists out the file • Similar to wc -l < filename >
file Determine file types • $file [Options] [Arguments] • Options -f filelist • Normal File Types • - C program text • - assembler program text • - commands text • - ASCII text • - English text • e.g., $ file test.c • C Program test
cp copy a file • -i - user interactive mode • e.g., • $ cp test.c test.c.bak • test.c and test.c.bak contain the same contents • Extra disk storage • In Create link • e.g., • $ ln first.c second.c • The file is referenced by two different names • No Extra disk storage