Objectives The Linux Operating System An Overview Nick Urbanik Copyright Conditions: GNU FDL (see http://www.gnu.org/licenses/fdl.html) Department of Information and Communications Technology Having completed this module, you will have an overview of a Linux system, including its: Underlying philosophy System layering — kernel vs. applications Core services Multiuser and timesharing facilities File System Network Services Desktop and X windowing system OSSI — Overview of Linux — ver. 1.0 – p. 1/27 OSSI — Overview of Linux — ver. 1.0 – p. 2/27 Generic Features of Unix Component-based systems Very popular with technically skilled Not ‘solution’ oriented Building blocks not the building Highly network-aware Robust, powerful, reliable Linux — The Kernel of a System Compilers DBMS Text Editors Mailers Graphics Apps Shells & Utilities X Windowing System Kernel Hardware Figure 1: kernel-layering OSSI — Overview of Linux — ver. 1.0 – p. 3/27 OSSI — Overview of Linux — ver. 1.0 – p. 4/27 What is called Linux is actually a collection of components from many sources Fundamental Characteristics of Linux Multi-tasking Multi-user access Multi-processor Architecture independence POSIX 1003.1 plus basic System V and BSD Protected memory mode Multiple filesystem types Comprehensive networking (TCP/IP and others) Multiple executable formats (MS-DOS, iBCS UNIX, SCO, etc) Multiuser Multitasking and Time-sharing Designed as a multi-user system Each user’s shells, apps and commands are separate processes Number of simultaneous users limited only by: CPU speed and available memory Min. response times required by users/apps Multi-tasking: Many jobs can be under way at the same time Jobs truly simultaneous on multi-cpu Time-sharing: A single cpu is shared by all processes Processes exec briefly, passing cpu to others Process switches occur in miliseconds or less Kernel gives process a sense of total control OSSI — Overview of Linux — ver. 1.0 – p. 6/27 OSSI — Overview of Linux — ver. 1.0 – p. 5/27 Protected memory mode Uses the processor’s protection mechanisms Prevent access to memory already allocated to kernel or other processes Bad programs can’t crash the system Theoretically Multiple Filesystem Types Native FS is ext3 (Third Extended File System) File names up to 255 chars More secure than conventional UNIX Others include: MS-DOS (FAT16), VFAT, FAT32 ISO9660 (CD-ROM) HPFS (OS/2) NTFS (Windows NT) reiserfs, XFS, other journalling file systems for Linux, UPS, SysV and other proprietory UNIX NFS (Unix network file system) SMB / CIFS (MS Windows file sharing) OSSI — Overview of Linux — ver. 1.0 – p. 7/27 OSSI — Overview of Linux — ver. 1.0 – p. 8/27 The Many Faces of a GNU/Linux System The user may see up to five aspects of Linux: the filesystem processes the shell the X windowing system Inter-Process Communication (IPC) The system is very highly configurable Different users may experience totally different views of the same system Multiple simultaneous users are normal Linux is designed from the ground up as a multi-user system, NOT a ‘personal’ system OSSI — Overview of Linux — ver. 1.0 – p. 9/27 The Filesystem The filesystem contains all data in the system A name in the filesystem can refer to: a data file, which can be: a plain file a directory a device (disk, tape etc.) internal memory OS information (the proc system) Directories are groups of files Grouped in hierarchical trees Files are fully specified with their pathname An original Unix structure; copied by most OSs OSSI — Overview of Linux — ver. 1.0 – p. 10/27 Filenames Maximum length depends on filesystem type Most allow up to 255 characters Can use almost any character in a filename, but avoid ambiguity by sticking to: (A-Z) Uppercase letters (a-z) Lowercase letters (0-9) Numbers (.) Full-stop (,) Comma (_) Underscore (-) Hyphen Should convey meaningful info about contents Type longer filenames using completion for: Filenames Pathnames OSSI — Overview of Linux — ver. 1.0 – p. 11/27 Filename Extensions and File Types Filenames don’t determine other attributes of file, i.e. do not, automatically, cause command interpreters to treat them in a particular way However: Extensions can enable meaningful naming and automatic file manipulation C compilers and some other programs do depend on specific file extensions to carry out particular tasks Common conventions for extensions: Filename program.c program.o Meaning of Extension C programming source file Object code OSSI — Overview of Linux — ver. 1.0 – p. 12/27 Hidden Filenames Filenames beginning with a full-stop are hidden Typically used: To hide personal configuration files To avoid cluttering dirs with rarely used files Every dir contains 2 special hidden files: The Shell (bash) A shell is a program that you interact with User . The current directory file Shell .. The parent directory file OSSI — Overview of Linux — ver. 1.0 – p. 13/27 Kernel OSSI — Overview of Linux — ver. 1.0 – p. 14/27 Key Features of the Bash Shell Command history Command aliasing Shell scripting Filename completion Command completion Command line editing (emacs and vi styles) Job control Key Bindings Directory stacking Tilde directory notation Help function, e.g. OSSI — Overview of Linux — ver. 1.0 – p. 15/27 Interacting with a Linux ‘Terminal’ Can be any program, but is normally a command Linux can support any number of ‘terminal’ types interpreter nowadays, monitor/keyboard combinations A command interpreter is usually started when you log previously, dumb terminals in (but this is just one way) occasionally, printers (debugging servers) The ‘standard’ Linux command interpreter is a Bourne Most look-alike called bash aa windowed terminal, but if shell will use the console or not: The command line syntax provided by bash enables Linux usually keeps a database manipulation of files & processes a of terminal capabilities in /etc/termcap The command-line frightens beginners but is the If your terminal type is not recorded in preferred home of the skilled /etc/termcap, you’ll have problems running certain programs e.g. a Bash has more functions than true Bourne shells; incorporating most of cursor driven apps (top, linuxconf, vi etc) the innovations added by the C and Korn shells. Bash functions and flags differ The environmental variable TERM tells programs between implementations of UNIX and Linux. The version of bash in current Linux what terminal type you are using OSSI releases tends to be the most fully functional Bourne shell around.— Overview of Linux — ver. 1.0 – p. 16/27 $ help history history: history [n] [ [-awrn] [filename]] a AT&T flavours of UNIX use /usr/lib/terminfo to store the same infor- Software Tools: The UNIX Philosophy True UNIX-like systems treat programs as tools Each tool should: Do just one thing well Be generic (untied to specific applications) For new jobs, build new tools (Re-)combine, don’t complicate old tools Linux can do this because it has: two simple objects: the file the process simple methods of connecting: processes to files processes to processes FILE 1 OSSI — Overview of Linux — ver. 1.0 – p. 17/27 Tasks/Processes A program is an executable object, stored in a file A process is an executing object, i.e. a an instance of a program currently being run Existing processes can ‘fork’ to create other processes the only way to make new processes A user may run multiple copies of same program Multiple users may run single/multiple copies System tracks ownership and permission a Processes are often called tasks, as in ‘multi-tasking’ OSSI — Overview of Linux — ver. 1.0 – p. 18/27 PROCESS Process Communication PROCESS FILE 2 Re-directing I/O to and from Files Most processes will take input from the keyboard and output to the screen Both input and output streams can be re-directed to/from files Output to a file (creating or overwriting): $ ls > my-system.txt Appending output to a file: $ who >> my-system.txt Processes may need to co-operate by sharing files signalling events direct transfer of data pipelines (data streams) synchronising with each other Linux provides facilities for: signals shared memory pipes, both named and unnamed semaphores and others Processes may use network connections for communication, permitting client-server model Common for shared services like printing OSSI — Overview of Linux — ver. 1.0 – p. 19/27 OSSI — Overview of Linux — ver. 1.0 – p. 20/27 Re-directing I/O to and from Files (continued) Take input from one file, output to another: $ sort < /etc/passwd > pwd.sorted who ls 20-1 passwd > < sort pwd.sorted > OSSI — Overview of Linux — ver. 1.0 – p. 21/27 >> Pipes & Tools pts/1 pts/2 pts/3 pts/4 Sep Sep Sep Sep 5 2 5 4 10:50 14:47 10:56 17:27 Linux tools act as filters: taking data from input streams, modifying it, sending it elsewhere expecting data to come from other tools producing output which any other tool can process, e.g. ASCII text One tool’s output is connected to another’s input: Indirectly, via a file created by the first tool Directly, via a pipe or pipeline For example, to page through a reverse-sorted version of your password file on screen: $ sort -r < /etc/passwd | less root root root root kenny khc kkc montague kenny khc kkc montague my−system.txt OSSI — Overview of Linux — ver. 1.0 – p. 22/27 my−system.txt Linux as a Programming Environment Hierarchical Filestore Extensive set of powerful tools for software production, admin and support A common system interface only one set of procedures to learn Processes interface with anonymous files programs output to files or devices identically Modular architecture provides for a completely customised OS, e.g. An OS dedicated solely to graphics rendering A general-purpose system on one floppy Flexible user interface allows for uniquely customised programming environments OSSI — Overview of Linux — ver. 1.0 – p. 23/27 Networking Linux is a network operating system. The Internet network protocols (TCP/IP) are implemented in the kernel Although other media are supported (e.g. radio, infra-red), links are usually across: Ethernet Serial Line (Point-to-point) Proprietory file/print serving protocols supported: Appletalk DECNET IPX / Novell Netware SMB / CIFS (MS Windows/NT) OSSI — Overview of Linux — ver. 1.0 – p. 24/27 TCP/IP A suite of Internet-standard protocols and apps for managing data transfers Depicted as a ‘stack’ hardware and transport control protocols at the bottom user applications (e.g. browsers) at the top Client-server apps provide facilities for: Remote login File transfer Resource sharing (e.g. expensive peripherals) Remote command execution Email (internet/intranet/extranet) Web browsing OSSI — Overview of Linux — ver. 1.0 – p. 25/27 Documentation Copious, but fragmented and/or duplicated Using the man pages (On-Line Manual) Use man to see man pages on a named command, e.g $ man date The result should be something like: Programmer’s Manual /usr/man info pages The classic ‘man pages’, first stop for skilled users, worth learning hypertext browsable texts, often identical or updated versions of man pages DATE(1) NAME FSF DATE(1) /usr/share/doc/program-name ascii/html docs installed with the named program Howtos www Tutorials on Linux-related topics, available on-line if installed (usually in /usr/share/doc) Recently-released programs are usually documented on authorised web sites, many (including older tools) are documented by third-party sites date - print or set the system date and time SYNOPSIS date [OPTION]... [+FORMAT] date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]] Table 2: Sources of Linux Documentation OSSI — Overview of Linux — ver. 1.0 – p. 26/27 DATE(1) Shows page is in manual section 1 Linux man pages divided into sections: To view a page from a certain section use: $ man -S section-number command-name Square brackets surround optional arguments OSSI — Overview of Linux — ver. 1.0 – p. 27/27