* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download CS3161 Operating System Principles
MTS system architecture wikipedia , lookup
Mobile operating system wikipedia , lookup
Plan 9 from Bell Labs wikipedia , lookup
Security-focused operating system wikipedia , lookup
Spring (operating system) wikipedia , lookup
Copland (operating system) wikipedia , lookup
Burroughs MCP wikipedia , lookup
Distributed operating system wikipedia , lookup
Unix security wikipedia , lookup
CS3161 Operating System Principles Instructor : Dr Chun Jason Xue Department of Computer Science Room Y6428 Telephone : 2788 9815 Email : [email protected] Course info: http://www.cs.cityu.edu.hk/~jasonxue/CS3161 CS3161 Operating System Principle 1 References (Text Book) Silberschatz, Galvin, Gagne, Operating System Concepts, Seventh Edition, John Wiley, 2006. Tanenbaum, Modern Operating Systems, Second Edition, Prentice-Hall, 2001. W Stallings, Operating Systems, Fifth Edition, Prentice-Hall, 2005. Deitel, Operating Systems, Third Edition Edition, Pearson Prentice Hall, 2004. Dhamdhere, Operating Systems, A Concept-based Approach, McGraw Hill International Edition, 2003. Law, Operating Systems, McGrawHill, 2007 CS3161 Operating System Principle 2 Evaluation of Course Course work: 30% 8 points for each of the first two assignments 14 points for the last assignment Working load is Not heavy A final exam: 70% CS3161 Operating System Principle 3 Course Outlines 1 Introduction 2 3 4 5 6 7 8 9 10 OS Design Approaches and Structures Process Management Scheduling Concurrent Process Interactions Deadlock Memory Management File Management , File and Directory Protection Secondary Storage Management Embedded Systems CS3161 Operating System Principle 4 1 What is an Operating System? A program that acts as an intermediary between a user of a computer and the computer hardware. Operating system goals: Execute user programs and make solving user problems easier. Make the computer system convenient to use. Use the computer hardware in an efficient manner. CS3161 Operating System Principle 5 1.1 Functions of Operating System (i) User/computer interface : to access the computing resources (processor, memory, I/O devices). Example - User can access I/O devices through user program. (ii) Sharing computing resources, and make it accessible to all users : (1) Processor sharing among processes for execution, (2) Sharing primary (main memory) and secondary memory (disk) among the users. (iii) Control functions : (1) Input/Output (I/O) device control (verify device status, provides queuing for multiple requests); (2) Processes execution, protection and security (protection between processes, against illegal intrusions). (iv) Communication and Networking functions : Communication between processors, processes, remote access network services. CS3161 Operating System Principle 6 1.2 Four Component of a Computer System CS3161 Operating System Principle 7 1.2.1 Operating System User Access End User – Access computer system through application programs, such as Word-processing application software. Programmer – Development of applications, accessing operating system services through utilities (programming language libraries, software tools and utilities) such as manipulation of files, control I/O devices. Operating System Designer – Access to computer hardware through development of device interfaces and drivers, system utilities, identify and prevent system errors, O/S updates. CS3161 Operating System Principle 8 1.2.2 Typical User Access to Hardware (1) End User requests Application Program to execute; (2) Application Program uses Operating System Functions and Utilities such as read input from keyboard, open file for input/output; (3) Operating System converts system functions into hardware requests and procedures such as control input/output; (4) Execution begins on Hardware. CS3161 Operating System Principle 9 1.3 Operating System Functions (Components) (i) Process Management Process represents a program (application) executing on a computer system. Process management involves in keep track of process execution status and to share out processor resource (fairly and efficiently). . . . . Creation and deletion of both user and system processes (programs); The suspension and resumption of processes; User initiates a job, operating system turns job into process for execution; Scheduling of job/process to utilize or sharing the processor; Job Scheduler chooses from all the jobs submitted to the system and decides which one will be allowed into the system or assigned any resource for it to be processed. Process Scheduler (in multiprogramming) decides which process gets the processor, when and how much. Allocate processor resource to a process by setting up necessary hardware registers, loading process code, setup workspace etc. (called Dispatching); Reclaim processor resource when process completed execution or terminates, or exceeds allowed amount of usage. The provision of mechanisms for Process synchronization Process communication Deadlock Handling . . . CS3161 Operating System Principle 10 1.3.1 Operating System Functions (Components) (ii) Memory Management To monitor usage of physical memory (main memory or RAM) and to share out memory among executing processes. . Keep track of memory resource What parts are in used and by which process; What parts are not in used (free memory). . For multiprogramming, decides which process gets memory, when it gets it and how much. . Allocate the memory (resource) when the process requests it and the policy of allocating it (how to share the memory among multiple requests). . Reclaim the memory resource, when the process no longer needs it or has been terminated. . Support memory overlays, process code relocation, virtual memory. CS3161 Operating System Principle 11 1.3.3 Operating System Functions (Components) (iii) Secondary-Storage Management The operating system is responsible to control disk storage to back up main memory, disk management activities including : . Buffering and Spooling to handle multiple I/O requests; . Storage Allocation strategies for files; . Free-space Management on disk; . Disk Scheduling – to reduce and optimize disk access time. (iv) I/O System Management The operating system is to hide the peculiarities of specific hardware from user such as : . A buffer-caching system; . A general device-driver interface; . Drivers for specific hardware devices (device driver must be registered by OS, when device interrupt, OS pass control to device driver). CS3161 Operating System Principle 12 1.3.4 Operating System Functions (Components) (v) File Management (File System) The operating system implements the file and directory logical storage structure and mapped onto physical devices (magnetic disk, magnetic tape, etc.). . The creation and deletion of files . Creation and deletion of directories . The support of primitives for manipulating files and directories . The mapping of files onto secondary storage . The backup of files on non-volatile storage media (vi) System Protection Operating system imposed and enforcement mechanisms for controlling the access of programs, processes, or users to the resources defined by a computer system. (vii)Networking Operating system with network support, can operate among a collection of connected and communicating (network) processors (each with its own memory and controlled devices) and provides the user with access to the various resources that controlled by the individual system. CS3161 Operating System Principle 13 1.4.1 Operating System Basics Simple Monitor A simple operating system aims to perform automatic job sequencing operations efficiently. The monitor is always resident in memory (resident monitor). Example: MS-DOS The simple monitor consists of : 1 2 3 Job Sequencing - automatically transferring control from one job to another. Loader - loading system and application program into memory. Control card Interpreter - to carry out instructions on the cards (command) at the point of execution (such as command.com in MSDOS). CS3161 Operating System Principle 14 1.4.2 Operating System Basics Loader Monitor Job sequencing Control card interpreter User program area Memory usage for a Simple Monitor system CS3161 Operating System Principle 15 1.4.3 Operating System Basics Operations of the monitor : 1 Automatic job sequencing, relied on control cards (Job Control Language to define programming language requirement, loading, execution and I/O requirements) for jobs; 2 Jobs with similar needs (language, software, resources) are batched together to improve efficiency; 3 Off-line operations (card reader /CD-ROM /barcode reader /magnetic tape /line-printer output) - spooling CS3161 Operating System Principle 16 1.4.4 Operating System Basics Buffering - technique used by OS to improve I/O efficiency. . A method of overlapping the I/O of a job with its own computation. . The resident monitor or device drivers include system I/O buffers for each I/O device. . Application programs that use the I/O devices cause only transfer to/from a system buffers. . For each I/O device needed for a process, a buffer is allocated. . Buffering helps to smooth over variations in the time it takes to process a record. Example : System buffers (set up by OS) enable a process to execute and generate I/O simultaneously, minimizing I/O delays. CS3161 Operating System Principle 17 1.4.5 Operating System Basics Spooling (SPOOL - Simultaneous Peripheral Operation On-Line) . Technique used by OS to enable device sharing among user processes. . Spooling uses the disk as a very large buffer, for reading on input devices and for storing output files (as input/output buffers) until the output devices are able to accept them. . A method of overlapping the I/O of one job with computation of other jobs. . Spooling also allows a pool of jobs on disk be selected by the operating system to be executed next (Job Scheduler used in batch processing). . Spooling improves performance and efficiency of the system and keeps both the CPU and I/O operates simultaneously. Example : Spooling implemented as printer queues to keep printer and CPU busy, while multiple processes can be generating printer output. CS3161 Operating System Principle 18 1.5.1 Operating System - Modes of Operation Batch Processing Systems a way to organise jobs around the computer before processing. All the required programs and data are separately collected (batch) and translated into a form suitable for the machine. It is then placed under the control of the system (Job Scheduler) so that it can take in the data as and when required (no time limits) and generate output to specified devices. . Some jobs by nature are particular suited to batch processing, such as payroll systems, financial/statistical data (daily, weekly, monthly batch operational cycles). . Batch processing involves sharing of resources efficiently with mixture of jobs that demand usage of CPU and I/O devices (Job Scheduler, Multiprogramming). . Batch job streams (on Multi-tasking systems) are used as background tasks (low priority jobs) to be executed whenever the processor is idle. . Batch processing does not provide any user interactions (response time) and processing time limits, is particularly suited for jobs with long processing time. CS3161 Operating System Principle 19 1.5.2 Operating System – Modes of Operation Real Time Systems (Embedded Systems) a dedicated type of system responds to external events, or event driven system. These systems must be in continuous operation (on-line). These systems response to the events would have to be accomplished within a certain time or the complete chain of data capture, processing and output of the processed information may have to be completed within a specified time. The speed of data being captured, processing information is known as the response time of the system. . Characteristics of a Real Time System : (i) Event Driven, (ii) Response Time critical (completed within a fixed time), (iii) Availability critical : On-line all the time, (iv) Design for its peak load, (v) Under-utilised most of the time. Example : Real time system controlling chemical plant or jet engine Real time system for Airline passenger reservation system CS3161 Operating System Principle 20 1.5.3 Operating System - Modes of Operation Multiprogramming systems A term given to a system that may has several processes in "state of execution" at the same time. A process is in a state of execution if the computation has been started but not been completed or terminated (error condition). Process 1 Processes co-exists in memroy for a multiprogramming system Process 2 Process 3 Operating System CS3161 Operating System Principle 21 1.5.4 Operating System - Modes of Operation For multiprogramming systems, the operating system support, . Several processes co-exist in memory requiring memory management and protection. . Multiple jobs in state of execution (job queues) require processor sharing (scheduling) and job switching (context switching) mechanism controlled by the operating system. . Concurrent processing (multiprogramming) also demands processes interactions, synchronization and communication and might caused deadlock situations. Examples : Multiprogramming system to control two processes to access a common data set (synchronization). Multiprogramming system to enable two processes to communicate during execution (communication). CS3161 Operating System Principle 22 1.5.5 Operating System - Modes of Operation Time Sharing (Multitasking) Systems . Logical extension of multiprogramming, to support multiple users. . Users interact with programs coexist in memory and in state of execution, while CPU switching between programs frequently. . Time sharing system provides interactive use of a computer system. . CPU scheduling and multiprogramming provide each user shared a small portion of processor time (CPU time slot), that provide user interaction (short response time). CS3161 Operating System Principle 23 1.6 Multiprocessing Systems Distributed computations among several physical processors. Hardware setup schemes : (1) Tightly coupled systems (Parallel systems) - processors share memory and clock, (2) Loosely coupled system (Distributed systems) - processors do not share memory and clock, each processor has its local memory but coordinate or communicate with each other through communication links. Characteristics and functions : (1) Resource sharing - sharing of storage, I/O devices, software or hardware and remote accessing; (2) Computation load sharing - partition job into sub-computations and distributed among various sites; (3) Reliability - redundancy exits in distributed system, individual break down should not affect the rest; (4) Communication - allow programs to exchange data or information CS3161 Operating System Principle 24 1.6.1 Multiprocessing Systems Modes of operation : Symmetric multiprocessing (SMP) each processor runs a copy of the O/S; many processors can run multiple processes; co-ordination between processors to avoid processor idle or overloading and allowing workloads to be shared dynamically; Example: WindowsNT (Version 4) support 4-way (processors) symmetric multiprocessing. Example : SUN OS Version 5 (Solaris 2) support symmetric multiprocessing (SMP). Asymmetric multiprocessing each processor assigned a specific task with a master-slave relationship; the master processor schedules and task scheduling to slave processors; used in extremely large systems to handle large number of simultaneous I/O devices (as front-end processor). Example : SunOS Version 4 provides asymmetric multiprocessing for resource sharing and network filing system. CS3161 Operating System Principle 25 1.6.2 Multiprocessing Systems . . Distributed Systems Multiple systems in a networked environment (LAN, WAN) – loosely coupled systems; Operating system support network protocol such as TCP/IP; Sharing computational loads, hardware and software; . Three types of distributed systems : . (1) Client-server systems – centralised system provides services (computing requests, filing services) to client systems (limited computation ability). (2) Peer-to-Peer systems – loosely coupled systems through networking providing exchange of information (emails), remote logon, file transfer, Internet access. (3) Clustered systems – loosely coupled systems, high speed networked together. Clustering software (on each node) monitors systems thus provides high availability function. CS3161 Operating System Principle 26 1.7 Operating System Kernel (Nucleus, Core) Operating System Kernel (Nucleus, Core) The operating system is a very large program and usually not possible to fit into the system memory (size and memory resource overhead). Some of the basic important functions: (i) resource control, (ii) starting and terminating process, (iii) basic I/O, (iv) interrupt handling function must be resident in memory and always be available – Operating System Kernel. Other system functions form a secondary system process layer loaded in on demand and removed on completion is called the Transient Program layer of the operating system. Example : MS-DOS operating system, Kernel functions (program) : DIR,TYPE,COPY.. Transient system functions (program): FORMAT,DISKCOPY,CHKDSK.. CS3161 Operating System Principle 27 1.8 Command Interpreter (Control Card Interpreter) Command Interpreter, a system program, is the user interface for MS-DOS PC system (Apple's Macintosh O/S system uses a window and menu that is almost exclusively mouse-based). - Command interpreter allows users to interact with the operating system to access user support system programs. - The command interpreter contains the codes to execute the command, sets up parameters, verifies correctness of usage then makes the appropriate system calls. Example : For MS-DOS, command interpreter (COMMAND.COM) located in the root directory. The command interpreter allows users to perform file manipulation functions such as file creation and manipulations. Example : edit (create file), del (delete), print, copy files. Example : MS-DOS, del filename command will check filename existence, then call system program to perform the file deletion. - In Unix the command interpreter, perform similar functions is called shell. CS3161 Operating System Principle 28 1.8 Command Interpreter (contd) - Command interpreter deals with process management, I/O handling, secondary-storage management, main memory management, filesystem access, protection and networking (user accessible system functions). - In larger system, command interpreter (control-card interpreter, job control language) allows jobs to be initiated automatically when a user is login (time-sharing systems) or used to control batch jobs. Example: In large data processing centre, JCL jobs help to generate financial reports daily and distribute to selected users. CS3161 Operating System Principle 29 1.9 System Programs & System Calls The operating system programs provide an environment for the execution of programs and to the user of those programs. A collection of system programs to support the operating system services and user application development through the use of system calls. . System calls (user support) provide the interface between a running program and the operating system. User program usually access system services by defined as assembly language functions. . Some systems allow system calls to be made directly from a user higher-level language program (called run-time support routine) such as the ‘C’ language run-time system library. Example : A getchar function in ‘C’ program is complied by the language compiler into a call to a run-time support routine that issues the necessary read system calls, check for errors and finally perform the read operation and return to user program. CS3161 Operating System Principle 30 1.9 System Programs & System Calls (contd) User system functions - accessible through system calls (examples are based on the UNIX system), can be grouped into : (1) Process control – enable user to control program (process) executionto-end, abort, load, execute process; create process, terminate process; get process attributes (attributes : process maximum execution time, process priority etc.), set process attributes; wait for time, wait event, signal event; request for allocation of free memory. Example : The exit system call to terminate a process. (2) File manipulation – enable user to create file, delete file; open, close file; read, write, reposition file; get file attributes (attributes : name, file-type, protection codes, accounting information etc.), set file attributes. Example : The open(…) system call will open a file with arguments (…). CS3161 Operating System Principle 31 1.9 System Programs & System Calls (contd) (3) Device manipulation – enable user to request device, release device; read, write, reposition device; get device attributes (name, ID, priority etc.), set device attributes; logically attach or detach devices. Example : The mount(…) system call allows users to access data in a disk section as a file system. (4) Information maintenance – enable user to get time, date; set time, date; get system data, set system data, get process, file or device attributes; set process, file, device attributes. Example : The setuid(uid) system call set the effective user ID for a process. (5) Communication – enable user to create, delete communication connection; send, receive messages; transfer status information, attach or detach devices. Example : The signal(…) system call inform process of the occurrence of asynchronous events. CS3161 Operating System Principle 32 1.9 System Programs & System Calls (contd) System Management Services (privileged functions) - not available to users, are used for efficient operation including : - Sharing of resources (such as CPU scheduling), - Allocation of resources (such as memory allocation, I/O devices), - System data and system log, error detection and protection. CS3161 Operating System Principle 33 1.10 User and Supervisor (Monitor) Modes of Operation To ensure protection on shared resources (such as I/O devices including printer, display devices) from user errors, whenever user makes requests to control devices such as performing I/O, there will be a change of operation mode, from user mode to supervisor (monitor) mode. All I/O instructions are privileged instructions and any user attempts will cause an error trap to O/S. . . MS-DOS do not support dual mode (Intel 8088/8086 processor limitation), user program can wipe out data, writing illegal data to devices. Modern hardware (Intel Pentium processor) and O/S (such as Windows NT) system provide dual mode operation with better protection. CS3161 Operating System Principle 34 1.10.1 Example on Dual Mode Operation (1) (2) (3) (4) (5) Dual mode – User mode and Supervisor (System, Privileged) mode involved in the operation. Example to show dual mode operations, on the case user process request data input from I/O device keyboard. User Mode User Process execute system call (I/O input); I/O Interrupt, mode switching. System Mode System Process to perform I/O (Interrupt Service Request): (i) Request I/O device; (ii) Setup buffer; (iii) Identify I/O device status, device interrupt address; (iv) Execute device driver; (v) Transfer data to buffer. Data on buffer transfer to user process buffer. System Process interrupt, control pass back to User Process CS3161 Operating System Principle 35 End of Introduction CS3161 Operating System Principle 36