The Linux System: Design Principles Linux is a multiuser, multitasking system with a full set of UNIX-compatible tools. Its file system adheres to traditional UNIX semantics, and it fully implements the standard UNIX networking model. Main design goals are speed, efficiency, flexibility and standardization. Linux is designed to be compliant with the relevant POSIX documents; some Linux distributions have achieved official POSIX certification. The Linux programming interface adheres to the SVR4 UNIX semantics, rather than to BSD behavior. 1.1 The layers of a UNIX system User Interface 1.2 Components of a UNIX System Like most UNIX implementations, Linux composed of three main bodies of code: is Standard Utilities Programs Standard Library Kernel Standard Utilities Programs perform individual specialized management tasks. Shell Commands for the management of files and directories Filters Compilers Editors Commands for the administration of the system … 1.3 The shell of a UNIX System The UNIX systems have a Graphical User Interface (Linux uses KDE, GNOME …), but the programmers prefer to type the commands. Shell: the user process which executes programs (command interpreter) User types command Shell reads command (read from input) and translates it to the operating system. Can run external programs (e.g. netscape) or internal shell commands (e.g. cd) Various different shells available: Bourne shell (sh), C shell (csh), Korn shell (ksh), TC shell (tcsh), Bourne Again shell (bash). The administrator of the system provides to the user a default shell, but the user can change shell. 1.4 The shell of a UNIX System Example of commands $ cd /usr/src/linux $ more COPYING $ cp file1 file2 $ head –20 file $ head 20 file $ ls *.c $ ls [abc]* $ sort < file1 > file2 String multiple commands together in a shell script $ sort < file1 > file2; head –30 < file2 ; rm temp $ sort < file | head –30 $ grep org CREDITS | sort | head –20 | tail –5 > file 1.5 The shell is more ... The shell is programmable, that is it possible to make the shell scripts A shell script is a file containing a sequence of commands addressed to the operating system that facilitates the repeated execution of the included commands without their having to be laboriously retyped each time they are executed. If there is a distinct ordered list of operating system commands that the user needs to execute repeatedly, for example, immediately after every login or immediately before every logout, then most operating systems have a facility for recording the list of commands in a file, which can then either be executed automatically upon login or logout, or can be invoked by the user through the issuance of a single command that results in the execution of the entire contents of the batch file, which can contain as few as one operating system command or as many as thousands. 1.6 The shell scripts Example: #!/bin/csh clear echo Menuset stop=1 while ($stop>0) cat << ENDOFMENU 1: stampa data 2: stampa la directory corrente 3: esci ENDOFMENU echo -n Scegli il comando set reply=$< switch ($reply) case 1 : date breaksw case 2 : pwd breaksw case 3 : set stop=0 breaksw default: echo scelta sbagliata riprova breaksw endsw end exit 0 1.7 UNIX Utility Programs A few of the more common UNIX utility programs required by POSIX 1.8 The Standard Library A system call is the method that the user process uses to ask for an action from the O.S. The programs perform the system calls by mean of trap. trap instruction: changes from user mode to kernel mode controls the correctness of the call parameters execution done on behalf of the operating system returns to user mode Since it is impossible to write a trap in C, it is provided a standard library with a procedure for each system call. These procedures are written in assembler and are called from C. For example a C program for performing the system call read, it calls the procedure read ,of the standard library. So, the standard library defines a standard set of functions through which applications interact with the kernel, and which implement much of the operating-system functionality that does not need the full privileges of kernel code. POSIX establishes which are the procedures of the library that the system has to provide, their parameters and tasks. 1.9 The Kernel The kernel is responsible for maintaining the important abstractions of the operating system. It provides the main functions of the abstract machine (system calls and Interrupt and traps). Approximate structure of generic UNIX kernel 1.10 The Kernel The Linux kernel uses a monolithic model. It does not take the “new” client-server model (i.e., microkernel). The main reason for this choice is the improvement of the performances. The kernel code is executed in kernel mode with full access to all the physical resources of the computer. All kernel code and data are contained in a unique address space. Although the kernel runs as a single process with a single address space, Linux kernel uses the modularity. 1.11 File System Linux files are organized by a hierarchy of labels, commonly known as a directory structure. The files referenced by these labels may be of three kinds: Regular files, which contains a sequence of bytes that generally corresponds to code (programs) or data. Directory files, which are stored on disk in a special format and form the backbone of the file system Special file, which correspond to peripherals such as printers or disks. To the user, Linux file system appears as a hierarchical semantics. directory 1.12 tree obeying UNIX File System / is the root directory; reference point for all directories. pathname: Every file /home/user1/papers 1.13 has a unambiguous Some directories found in UNIX systems /bin Binaries which are absolutely essential to run Linux. /boot All the files required for booting Linux on a system. /dev All the devices have their corresponding files here. /etc All the configuration files for the various software are stored here. Don't play with this directory. /home All users will have their 'My Documents' under this directory. If your id is rossi, your 'My Documents' (called home-directory) is /home/rossi. /lib The libraries required by system-applications. (Just like DLLs in Windows.) /lost+found When a disk-check finds files which are damaged or which are not linked to any directory, they are recovered to this directory. Such damages are almost always due to incorrect shutdown. 1.14 Some directories found in UNIX systems /mnt The directory where peripherals and other file systems are mounted. /opt The directory where optional software are installed. /proc proc houses a pseudo-file system. Its contents really do not exist anywhere on the disk, and are made available only when you cd to this directory and look at some file. /root The home-directory for the super-user: root. /sbin The system-administration binaries exist here. /tmp The directory where temporary files are created and stored. All users can save files here. /usr Everything related to users /var Files whose contents vary frequently are in this directory. 1.15 Some directories found in UNIX systems /usr Everything related to users /usr/bin houses critical binaries of the users /usr/include The header-files required by programs for compilation. /usr/lib The libraries required by user-applications. /usr/local Files peculiar to this particular machine. /usr/sbin User-administration binaries. /usr/share Information that can be shared by most users. /usr/src The source-code for the Linux kernel. /usr/X11R6 Files needed by the X Window system. /var Files whose contents vary frequently are in this directory. /var/log The log-files of the system. /var/spool Directories for mail, news, printing and other queued work. 1.16 Mounting Separate file systems After mounting Before mounting After mounting 1.17