890 likes | 1.39k Views
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
E N D
Chapter 15UNIX and Linux Operating Systems 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 • The differences between command-driven and menu-driven interfaces • The roles of the Memory, Device, and Processor Managers Understanding Operating Systems, Fourth Edition
Overview • UNIX and Linux share three major advantages: • Portable from large systemsto 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 Understanding Operating Systems, Fourth Edition
Overview • 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 Understanding Operating Systems, Fourth Edition
The Evolution of UNIX Table 15.1: Evolution of UNIX Understanding Operating Systems, Fourth Edition
The Evolution of UNIX (continued) Table 15.1 (continued):Evolution of UNIX Understanding Operating Systems, Fourth Edition
The Evolution of UNIX (continued) Table 15.1 (continued):Evolution of UNIX Understanding Operating Systems, Fourth Edition
The Evolution of UNIX (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 Understanding Operating Systems, Fourth Edition
The 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 userinterfaces Understanding Operating Systems, Fourth Edition
The Evolution of Linux (continued) Table 15.2:Major releases ofLinux by Red Hat, Inc. Understanding Operating Systems, Fourth Edition
The Evolution of Linux (continued) Table 15.2 (continued):Major releases ofLinux by Red Hat, Inc. Understanding Operating Systems, Fourth Edition
The Evolution of Linux (continued) Table 15.2 (continued):Major releases ofLinux by Red Hat, Inc. Understanding Operating Systems, Fourth Edition
Design Goals • Linux and UNIX share similar design goals: • Develop an operating system that would supportsoftware 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 Understanding Operating Systems, Fourth Edition
Design Goals (continued) Table 15.3:Systemfunctions supported in Linux and UNIX Understanding Operating Systems, Fourth Edition
Design Goals (continued) Table 15.3 (continued):Systemfunctions supported in Linux and UNIX Understanding Operating Systems, Fourth Edition
UNIX 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 Understanding Operating Systems, Fourth Edition
UNIX Memory Management (continued) Figure 15.1:Typical internal memory layout for single user-memory partUNIX image Understanding Operating Systems, Fourth Edition
UNIX Memory Management (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 Understanding Operating Systems, Fourth Edition
UNIX Memory Management (continued) • Data Segment: • Starts after program code and grows towardhigher memory locations • Nonsharable section of memory • Stack: • Starts athighest memory address and grows downward as subroutine calls and interruptsadd information to it • Section of main memory where process informationis saved when process is interrupted • Nonsharable section ofmemory Understanding Operating Systems, Fourth Edition
UNIX Memory Management (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 Understanding Operating Systems, Fourth Edition
Linux Memory Management • Allocates memory space to each process • e.g., In Intel X86, Linux allocates 1 GB of high ordermemory to kernel and 3 GB of memory to executing processes • Address spaceis divided among: • Process code • Process data • Code and shared library data used by process • Stack used by process Understanding Operating Systems, Fourth Edition
Linux Memory Management (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 Understanding Operating Systems, Fourth Edition
Linux Memory Management (continued) • If any pages marked for deletion have been modified, they’re rewritten to disk • Page corresponding to file mapped into memory is rewrittento 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 Understanding Operating Systems, Fourth Edition
Processor 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 runfirst • Any processes that have used a lot of CPU time will get lower priority than those thathave not • System updates compute-to-total-time ratio for each job everysecond Understanding Operating Systems, Fourth Edition
Processor Management (continued) • If several processes have same computed priority,they’re handled round-robin • Process with longest timespent 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 makeroom for new arrival • UNIX dynamically recalculates all process priorities to determinewhich inactive but ready process will begin execution when processor becomesavailable Understanding Operating Systems, Fourth Edition
Process Table Versus User Table • UNIX uses several tables to keep system running smoothly • Information on simple processes, those with nonsharable code, is stored in twosets 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 Understanding Operating Systems, Fourth Edition
Process Table Versus User Table (continued) Figure 15.2:Process control structureshowing how process table and texttable interact forprocesses with sharablecode, as well as for thosewithout sharable code Understanding Operating Systems, Fourth Edition
Process Table Versus User Table (continued) Process Table: • Each entry contains following information: • Process identificationnumber • User identification number • Process memory address or secondary storageaddress • Size of process and scheduling information • Process table is set up when process is created and is deleted when process terminates Understanding Operating Systems, Fourth Edition
Process Table Versus User Table (continued) Text Table: • For processes with sharable code, process table maintains a text table, which contains: • Memory address or secondarystorage 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 Understanding Operating Systems, Fourth Edition
Process Table Versus User Table (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 Understanding Operating Systems, Fourth Edition
Synchronization • UNIX is true multitasking operating system • Achieves process synchronization byrequiring that processes wait for certain events • Each event is represented by integers equal to address oftable associated with event • A race may occur if event happens during process’s transition between decidingto wait for event and entering WAIT state Understanding Operating Systems, Fourth Edition
fork • fork:Capability of executing oneprogram from another program • Gives secondprogram all attributes of first program, such as any open files, and savesfirst 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 Understanding Operating Systems, Fourth Edition
fork (continued) Figure 15.3:When fork commandis received, parentprocess shown in (a)begets child processshown in (b) andStatement 2 is executedtwice Understanding Operating Systems, Fourth Edition
wait • 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 Understanding Operating Systems, Fourth Edition
wait (continued) Figure 15.4: wait command usedin conjunction with fork command synchronizes parent andchild processes. (a) shows parentprocess, (b) shows parent and child after fork, and (c) shows parent and child duringwait Understanding Operating Systems, Fourth Edition
exec • 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 Understanding Operating Systems, Fourth Edition
exec (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 Understanding Operating Systems, Fourth Edition
Linux Process Management • Linux supports the concept of “personality” to allow processes coming from otheroperating systems to be executed • Each process is assigned to anexecution 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 Understanding Operating Systems, Fourth Edition
Linux Process Management (continued) • Clone process is created using primitive “clone,” by duplicating its parentprocess • Allows both processes to share same segment ofcode and data • Modification of one is visible to other, which is unlike classicalprocesses • Ability to clone processes brings possibility of implementing serversin which several threads may be executing Understanding Operating Systems, Fourth Edition
Organization 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 Understanding Operating Systems, Fourth Edition
Process Synchronization • To allow two processes to synchronizewith 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 Understanding Operating Systems, Fourth Edition
Device Management • UNIX and Linux aretruly device independent • Both treateach I/O deviceas 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 commonperipheral devices Understanding Operating Systems, Fourth Edition
Device Management (continued) • Actual incorporation of device driver into kernel is done during systemconfiguration • Recent versions of UNIX have program called config that automatically createsconf.c file for any given hardware configuration • Contains parameters that control resources such as number of internal bufferfor kernel and size of swap space • Contains twotables: • bdevsw (short for “block I/O devices”) • cdevsw (short for “character I/Odevices Understanding Operating Systems, Fourth Edition
Device 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 intodevice drivers Understanding Operating Systems, Fourth Edition
Device Classifications (continued) Figure 15.6:The hierarchy of I/O devicesin UNIX and Linux Understanding Operating Systems, Fourth Edition
Device Classifications (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 Understanding Operating Systems, Fourth Edition
Device Classifications (continued) • Devices in character class are handled by device drivers that implement characterlists • Example: A terminal is typical character device that has two input queues and one outputqueue • 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 Understanding Operating Systems, Fourth Edition
Device Drivers • Special section in kernel, which includes all the instructions necessary for OS tocommunicate with device • Device drivers for disk drives use a seek strategy tominimize the arm movement • Kept in a set of files: • Can be loaded as needed, in case of seldomused devices • Can be kept in memory all the time when operating systemboots • Kept in /dev directory by default and convention Understanding Operating Systems, Fourth Edition
File 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 Understanding Operating Systems, Fourth Edition
File Management (continued) • Ordinary files: Files in which users store information • Protection is based onuser’s requests • Related to read, write, execute, and delete functions that canbe 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 themreside in /dev directory • Name of each special file indicates type of devicewith which it’s associated Understanding Operating Systems, Fourth Edition