Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Operating System Principles AUA CIS331 Albert Minasyan Operating Systems Principles (Introduction) The purpose of the operating system is to run the user program on the computer. Nowadays everywhere are being used different types of computers for different purposes. All they need operating systems to perform their tasks. Starting from very small computers inside the handheld devices and finishing with huge supercomputers in data centers have their operating systems. But surprisingly all those different operating systems have the same basic principles. This course describes that basic principles and allows to understand the differences between the operating systems and the reasons why this or that operating system is being used on different computers or computer systems. 1 Operating System Principles AUA CIS331 Albert Minasyan Sources: • • • • This course structure OS Introduction Processes, Threads, Scheduling, Synchronization Memory management I/O systems Interrupts Operating Systems Yale university UC Berkeley JHU My experience File Systems Protection and Security Distributed Processing Networks Different OS comparison Exercises, Assignments, Project (C, C++) WinAPI Linux API Windows OS Real Workstation Linux OS Virtual Machine Student’s should complete programming assignments on “Unix and Windows Processes and Threads programming on C, C++” Required Textbook: Silberschatz, Galvin, Gagne “Operating System Concepts”, 9th edition. 2012 Kay A. Robbins, Steven Robbins, Unix Systems Programming, 2003 Recommended Reference Books: Herbert Schildt. Windows 95 Programming in C and C++. 1995 Herbert Schildt. Windows 2000 Programming from the Ground Up. 2000. Kate Gregory. Using Visual C++ 6. 2 Operating System Principles AUA CIS331 Albert Minasyan Goal of this handout: to teach the differences of main types of OS and the evaluation criteria of OS. Outcome: Students should distinguish the different types of OS/computer systems and be able to apply the evaluation criteria to different types of OS and evaluate different systems’ performance. Handout Content: 1.1. What is an Operating System 1.2. Computer system types and description o 1.2.1. Mainframe Computer Systems 1.2.1.1. Batch Systems 1.2.1.2. Multiprogrammed Systems 1.2.1.3. Time Sharing Systems o 1.2.2. Desktop Systems o 1.2.3. Multiprocessor Systems Tandem, Symmetric, Asymmetric multiprocessor systems o 1.2.4. Distributed Systems 1.2.4.1. Client Server Systems 1.2.4.2. Peer-to-Peer Systems o 1.2.5. Clustered Systems o 1.2.6. Real Time Systems o 1.2.7. Handheld Systems Textbook Silberschatz, Chapter 1 1.1. What is an Operating System The purpose of the operating system is to run the user program(s). The three main responsibilities of an operating system: To provide an environment for a computer user to execute programs on computer hardware in a convenient and efficient manner (Shells, Windows, Terminals, Executable files concept). To allocate the separate resources (memory, processor, disk space, I/O device usage) of the computer as needed to solve the problem given. The allocation process should be as fair and efficient as possible. As a control program it serves two major functions: o supervision of the execution of user programs to prevent errors and improper use of the computer (protection of OS and programs from user programs). o management of the operation and control of I/O devices (device drivers, file systems) An operating system is a program that manages the computer hardware and acts as an intermediary between the user applications and the computer hardware. The operating system must ensure the correct operation of the computer system. To prevent user programs from interfering with the proper operation of the system, the hardware must provide appropriate mechanisms. The operating system provides certain services to programs and to the users of those programs in order to make their tasks possible and easier. The services differ from one operating system to another, but we identify and explore some common classes of these services. An operating system is an important part of almost every computer system. A computer system can be divided roughly into four components: the hardware, the operating system, the application programs, and the users. 3 Operating System Principles AUA CIS331 User 1 Albert Minasyan User 2 Compiler Assembler User 3 User n Text editor Database System System and application programs Operating System Computer Hardware Abstract view of the components of a computer system. The hardware - the central processing unit (CPU), the memory, and the input/output (I/O) devices provides the basic computing resources. The application programs-such as word processors, spreadsheets, compilers, and web browsers define the ways in which these resources are used to solve the computing problems of the users. The operating system controls and coordinates the use of the hardware among the various application programs for the various users. The operating system provides the means for the proper use of the resources of the computer system. User Application Programs Trying to use Computing Resources Using ready solutions is possible (is effective) API to OS for User Applications Operating System Device drivers Direct usage is possible (but is not effective) Control API to Hardware Computing Resources are provided by Computer Hardware (CPU, Memory, I/O devices) An application programming interface (API) is a set of functions, procedures, methods or classes that an operating system, library or service provides to support requests made by computer programs. The operating system is similar to a government. Like a government, it performs no useful function by itself. It simply provides an environment within which other programs can do useful work. 4 Operating System Principles AUA CIS331 Albert Minasyan 1.2. Computer System types and description The newest computers repeat the history of old computers starting from the very simple software and growing to full multiprocessor OS. All OS solutions invented tens of years ago are applicable for newest computers. 1.2.1. Mainframe Computer Systems Mainframe computer systems were the first computers used to tackle many commercial and scientific applications. They grew of from simple batch systems, where the computer runs one - and only oneapplication, to time-shared systems, which allow for user interaction with the computer system. Mainframe Computer Systems Desktop Computer Systems Operating Systems Batch Systems Multiprogrammed Systems Time Sharing Systems Tasks are collected in queues (pools) If CPU is idle it takes another (next or previous unfinished) task’s some part to be busy all the time CPU switches between tasks (programs) when it is idle and usually is busy all the time. Tasks are collected in queues. CPU takes and runs the parts of tasks from queue giving equal or appropriate time to each of task in order to serve all tasks from the queue. CPU switches between queue tasks after equal or predefined intervals of time and usually is never idle. User interaction with the programs is possible OS improves Tasks are collected in similar tasks’ batches Next task from batch runs when the previous one is finished fully CPU is dedicated for one task and is often idle 5 Operating System Principles AUA CIS331 Albert Minasyan 1.2.1.1 Batch Systems Early computers were physically enormous machines run from a console. The common input devices were card readers and tape drives. The common output devices were line printers, tape drives, and card punches. Batch of Tasks (Jobs) CPU Input Task #1 Input Calculation Output Save Result Task #2 Input Calculation Output Save Result Task #3 Read Calculation Output Save Result Output Read Save Disks Tapes The user did not interact directly with the computer systems. Rather, the user prepared a job-which consisted of the program, the data, and some control information about the nature of the job (control cards)-and submitted it to the computer operator. The job was usually in the form of punch cards. At some later time (after minutes, hours, or days), the output appeared. The output consisted of the result of the program, as well as a dump of the final memory and register contents for debugging. The operating system in these early computers was fairly simple. Its major task was to transfer control automatically from one job to the next. The operating system was always resident in memory. To speed up processing, operators batched together jobs with similar needs and ran them through the computer as a group. Memory layout for batch system Disadvantage: In this execution environment, the CPU is often idle, because the speeds of the mechanical I/O devices are intrinsically slower than are those of electronic devices. Even a slow CPU works in the microsecond range, with thousands of instructions executed per second. A fast card reader, on the other hand, might read 1200 cards per minute (or 20 cards per second). Thus, the difference in speed between the CPU and its I/O devices may be three orders of magnitude or more. Over time, of course, improvements in technology and the introduction of disks resulted in faster I/O devices. However, CPU speeds increased to an even greater extent, so the problem was not only unresolved, but exacerbated. 6 Operating System Principles AUA CIS331 Albert Minasyan 1.2.1.2 Multiprogrammed Systems Mainframe computer systems were very huge and expensive. The expensive system requires the most effective usage of expensive resources - especially the processor. That was why the main purpose of the MainFrame OS was to utilize the processor by all means. Thus appear the Multiprogrammed OS. The most important aspect of job scheduling is the ability to multiprogram. A single user cannot, in general, keep either the CPU or the I/O devices busy at all times. Advantage: Multiprogramming increases CPU utilization by organizing jobs so that the CPU always has one to execute. CPU Scheduling Task #1 CPU Input Read Calculation Output Output Read Task #2 Jobs in memory Input Calculation Output Save W Disks Tapes Task #3 Job Scheduling Read Wait Calculation Output W Job pool on Disk Memory management Resource Protection The idea is as follows: The operating system keeps several jobs in memory simultaneously. This set of jobs is a subset of the jobs kept in the job pool-since the number of jobs that can be kept simultaneously in memory is usually much smaller than the number of jobs that can be in the job pool. The operating system picks and begins to execute one of the jobs in the memory. Eventually, the job may have to wait for some task, such as an I/O operation, to complete. In a non-multiprogrammed system, the CPU would sit idle. In a multiprogramming system, the operating system simply switches to, and executes, another job. When that job needs to wait, the CPU is switched to another job, and so on. Eventually, the first job finishes waiting and gets the CPU back. As long as at least one job needs to execute, the CPU is never idle. Memory layout for multiprogramming system 7 Operating System Principles AUA CIS331 Albert Minasyan Multiprogramming is the first instance where the operating system must make decisions for the users. Multiprogrammed operating systems are therefore fairly sophisticated. All the jobs that enter the system are kept in the job pool. This pool consists of all processes residing on disk awaiting allocation of main memory. If several jobs are ready to be brought into memory, and if there is not enough room for all of them, then the system must choose among them. Making this decision is job scheduling, which is discussed later. When the operating system selects a job from the job pool, it loads that job into memory for execution. Having several programs in memory at the same time requires some form of memory management. In addition, if several jobs are ready to run at the same time, the system must choose among them. Making this decision is CPU scheduling. Finally, multiple jobs running concurrently require that their ability to affect one another be limited in all phases of the operating system, including process scheduling, disk storage, and memory management. Disadvantage: Multiprogrammed, batched systems provided an environment where the various system resources (for example, CPU, memory, peripheral devices) were utilized effectively, but it did not provide for user interaction with the computer system. Problems: Job and CPU scheduling, Memory management, different tasks resources protection issues should be taken in account to keep the system effective. 1.2.1.3. Time Sharing Systems Time sharing (or multitasking) is a logical extension of multiprogramming. Advantage: The CPU executes multiple jobs by switching among them, but the switches occur so frequently that the users can interact with each program while it is running. Processes in Physical Memory CPU Process #1 Input Calculation Input Output Calculation Output Save Result CPU time sharing Process concurrent execution Input Process #2 Input Calculation Output Save Result Output Process #3 Read Calculation Output Physical Save Result Memory Read Save Disks File system Users Security Memory management and protection Paging Virtual Memory 8 Operating System Principles AUA CIS331 Albert Minasyan Disadvantage: Time-sharing operating systems are even more complex (difficult, expensive) than multiprogrammed operating systems. Problems: Job and CPU scheduling, Memory management, User and Security management, Protection issues should be taken in account to keep the system effective. An interactive (or hands-on) computer system provides direct communication between the user and the system. The user gives instructions to the operating system or to a program directly, using a keyboard or a mouse, and waits for immediate results. Accordingly, the response time should be short typically within 1 second or so. A time-shared operating system allows many users to share the computer simultaneously. Since each action or command in a time-shared system tends to be short, only a little CPU time is needed for each user. As the system switches rapidly from one user to the next, each user is given the impression that the entire computer system is dedicated to her use, even though it is being shared among many users. A time-shared operating system uses CPU scheduling and multiprogramming to provide each user with a small portion of a time-shared computer. Each user has at least one separate program in memory. A program loaded into memory and executing is commonly referred to as a process. When a process executes, it typically executes for only a short time before it either finishes or needs to perform I/O. I/O may be interactive; that is, output is to a display for the user and input is from a user keyboard, mouse, or other device. Since interactive I/O typically runs at "people speeds," it may take a long time to complete. Input, for example, may be bounded by the user's typing speed; seven characters per second is fast for people, but incredibly slow for computers. Rather than let the CPU sit idle when this interactive input takes place, the operating system will rapidly switch the CPU to the program of some other user. In both, several jobs must be kept simultaneously in memory, so the system must have memory management and protection. To obtain a reasonable response time, jobs may have to be swapped in and out of main memory to the disk that now serves as a backing store for main memory. A common method for achieving this goal is virtual memory, which is a technique that allows the execution of a job that may not be completely in memory. The main advantage of the virtual-memory scheme is that programs can be larger than physical memory. Further, it abstracts main memory into a large, uniform array of storage, separating logical memory as viewed by the user from physical memory. This arrangement frees programmers from concern over memory-storage limitations. Time-sharing systems must also provide a file system (as should be done by any OS). The file system resides on a collection of disks; hence, disk management must be provided. Also, time-sharing systems provide a mechanism for concurrent execution, which requires sophisticated CPU-scheduling schemes. To ensure orderly execution, the system must provide mechanisms for job synchronization and communication, and it may ensure that jobs do not get stuck in a deadlock, forever waiting for one another. The idea of time sharing was demonstrated as early as 1960, but since time-shared systems are difficult and expensive to build, they did not become common until the early 1970s. Although some batch processing is still done, most systems today are time sharing. Accordingly, multiprogramming and time sharing are the central themes of modern operating systems, and they are the central themes of this course. 9 Operating System Principles AUA CIS331 Albert Minasyan System Evaluation Criteria CPU utilization (maximize) – keep the CPU as busy as possible Throughput (maximize) - # of processes that complete their execution per time unit Turnaround time (minimize)– amount of time to execute a particular process CPU utilization: the time the CPU is busy during some time period. We want to keep the CPU as busy as possible. CPU utilization may range from 0 to 100 percent. In a real system, it should range from 40 percent (for a lightly loaded system) to 90 percent (for a heavily used system). Throughput: If the CPU is busy executing processes, then work is being done. One measure of work is the number of processes completed per time unit, called throughput. For long processes, this rate may be 1 process per hour; for short transactions, throughput might be 10 processes per second. Turnaround time: From the point of view of a particular process, the important criterion is how long it takes to execute that process. The interval from the time of submission of a process to the time of completion is the turnaround time. Turnaround time is the sum of the periods spent waiting to get into memory, waiting in the ready queue, executing on the CPU, and doing I/O. Task 1 Resource Usage Table Batch System Seconds CPU HDD Prin ter 1 T1 2 T1 3 T1 4 T1 5 T1 6 T2 7 T2 8 T2 9 T2 10 T2 11 T2 12 T3 13 T3 14 T3 15 T3 Sec CPU time. Calculations. I/O time. Input from the HDD CPU time. Calculations. 1 2 2 Task 2 Sec CPU time. Calculations. I/O time. Input from the HDD CPU time. Calculations. I/O time. Print on Printer. 2 1 1 2 Task 3 Sec CPU time. Calculations. I/O time. Output to HDD. CPU time. Calculations. 1 2 1 Resource Usage Table Time Sharing System For external devices if the task takes the resource it keeps the resource until completing the operation with it. Seconds 1 2 3 4 5 6 7 8 9 10 CPU T1 T2 T3 T2 T1 T3 T1 T2 HDD CPU queue T2,T3 T2,T3 T2,T3 T2,T3 T2,T3 T3 T3 T3 T3 T3 T3 Printer T1 T1 T3 T3 T2 CPU queue T2,T3 T3 T2 T1 HDD queue T2 T1 T2 T2 T2 Resource Usage Table Multiprogrammed System The resource is dedicated if it’s free and if there is a request Seconds CPU HDD Printer CPU queue T2,T3 1 T1 T1 T3 2 T2 T1 T3 3 T2 T2 T1 4 T3 T3 T2 5 T1 T3 T2 6 T1 T3 7 T2 T2 8 T3 T2 9 10 10 Operating System Principles AUA CIS331 Batch Multiprogr ammed Time Sharing Albert Minasyan Overall time for all 3 tasks to finish 15 9 Throu ghput Task2 Turnaround time 11 9 Task3 Turnaround time 15 8 Average Turnaround time for all tasks (15+11+5)/3=10.3 (6+9+8)/3=7.67 CPU utilization 3/15 3/9 Task1 Turnaround time 5 6 10 3/10 7 10 6 (7+10+6)/3=7.67 8/10~80% 8/15 ~53% 8/9~89% 11