* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Chapter_7
Survey
Document related concepts
Transcript
Chapter 7 Operating Systems ©Brooks/Cole, 2003 OBJECTIVES After reading this chapter, the reader should be able to: Define the purpose and functions of an operating system. Understand the components of an operating system. Understand the concept of virtual memory. Understand the concept of deadlock and starvation. List some of the characteristics of popular operating systems such as Windows 2000, UNIX, and Linux. ©Brooks/Cole, 2003 Figure 7-1 Computer System Hardware is the physical devices but Software is the collection of Programs that allows the hardware to do its job. ©Brooks/Cole, 2003 7.1 DEFINITION ©Brooks/Cole, 2003 Note: An operating system is an interface between the hardware of a computer and the user (program or human) that facilitates the execution of the other programs and the access to hardware and software resources. ©Brooks/Cole, 2003 7.2 EVOLUTION ©Brooks/Cole, 2003 -Batch Systems. The programmer does not have any control or interactions during the execution of his Jobs (programs). -Time-Sharing Systems efficiently use computer resources because it allows several programs to share resources. Each program is allowed to use the resource only if it is available and also for a portion of time. Therefore, OS do scheduling: Allocating the resources to different programs and deciding which program should use which resource when. - Personal Systems serve single user and needs single-user operating system (e.g DOS). - Parallel Systems with multiple CPU on the same machine serve one or more programs in parallel but with more speed. -Distributed Systems allows programs to run partially on one computer and partially on another computer on networks ©Brooks/Cole, 2003 7.3 COMPONENTS ©Brooks/Cole, 2003 Figure 7-2 Components of an operating system Today Operating systems are very complex. In order to manage resources An OS has at least 4 manager where each one manages one resource But can cooperate with others. Users can communicate with OS either directly or through user Interface. ©Brooks/Cole, 2003 Figure 7-3 Memory Manager Memory is a limited resource that should Monoprogramming be managed efficiently. In order to run Programs, memory manager allocates enough memory for programs and data. -There are two categories of memory management: mono- and multi-programming 1- Monoprogramming: -It allows one and only one Program to be in memory! It loads a program into memory, run it, and replace it with the next program when it is finished. -Program size can NOT exceed the size of Memory! - Very inefficient usage of memory and CPU ©Brooks/Cole, 2003 Figure 7-4 Memory Manager 2- Multirogramming: Multiprogramming -More than one program can be in memory at the same time and are executed Concurrently. The CPU switches between Programs. -When I/O operations are executed by a running program, CPU is not idle but can schedule another program to run. -It uses memory and CPU efficiently. -It uses different techniques (swapping,…) ©Brooks/Cole, 2003 Figure 7-5 Categories of multiprogramming -Nonswapping means that the programs remains in memory for the duration of execution. -Swapping means that the program can be swapped between memory and disk one or more times during execution ©Brooks/Cole, 2003 Figure 7-6 Partitioning Memory is divided into variable length sections (partitions). Each section holds one program NOT part of it. The CPU switches between programs. Partitioning improves CPU efficiency but it suffers from : 1- if partition size is set too small, some programs can't be loaded into memory and if it is set too large, holes (unused locations) will be created. 2- Holes may be created after programs are replaced by new ones 3- Removing holes and create new partitions creates extra overhead. ©Brooks/Cole, 2003 Figure 7-7 Paging Paging improves the efficiency of partitioning. In paging memory is divided into equally sized sections called frames and programs are divided into equally sized sections called pages. Page size usually equal frame size. Pages of entire program needs enough frames(not necessary contiguou in memory to run. To improve paging, several variants techniques do exist: 1-Demand paging: The entire program does not need to be in memory to ru but pages can be loaded into memory one by one. 2- Demand segmentation: The program is divided into segments (modules) and loaded into memory, executed, and replaced by another module of the program or another 3-Demand Paging & segmentation memory is divided into frames & a module can be divided into pages ©Brooks/Cole, 2003 Figure 7-8 Virtual memory Demand paging and Demand segmentation means that part of the program is in memory and part is on disk. Example: a memory of 10 MB (physical memory) can execute 10 programs, each of 3 MB for total of 30 MB (virtual memory). At any moment 10MB Of the 10 program are in memory and 20MB on disk. ©Brooks/Cole, 2003 Process Manager A second function of an OS is process management. To understand process management we need to define the following: -Program is a nonnative set of instructions written by programmer and stored on disk (or tape). It may or may not become a job. -A program becomes a JOB from the moment it is selected for execution until it has finished running and becomes a Program again! -Process is a program in execution. It is a program that has started but not finished. It is a job that is residing in memory ©Brooks/Cole, 2003 Figure 7-9 State diagram with the boundaries between a program, a job, and a process A program becomes a Job when OS selects it and brought it into Hold state. When there is enough memory to load the program totally or partially, the job becomes a process and moves to the Ready state. The process remains in this state until CPU is given to it and it moves to running state. It remains there until it needs I/O or its allocated slot of time is finished or process terminate. ©Brooks/Cole, 2003 Figure 7-10 Job scheduler To move a job or process from one state to another, the process manager uses 2 schedulers; job and process schedulers. -JOB SCHEDULER moves a job from hold state (create a process) to ready state or from running state to the terminate state. ©Brooks/Cole, 2003 Figure 7-11 Process scheduler It moves a process from one state to another. It moves a process from running to waiting if it waits for some events to happen. It moves a process from Running to Ready if time allotment has expired. It moves a process from waiting to ready if the event has occurred. It moves a proces from ready to Running if CPU is available. ©Brooks/Cole, 2003 Figure 7-12 Queues for process management To handle multiple processes and jobs competing for resources, process Manager uses QUEUES (waiting lists). Associated with each process or Job is a job or process control block (JCB or PCB)that stores information about each Job or process. OS stores JCB or PCB in the queues and leaves the jobs or processes themselves on disk. OS can use different policies for selecting the next job or process from a queue. Examples are FIFO or Shortest Length First or one with highest priority, and so on. ©Brooks/Cole, 2003 Process Synchronization The whole idea behind process management is to synchronize different processes with different resources. When resources can be used by more than one user (process), 2 situation arise namely deadlock and starvation. Those situations should be avoided. -Deadlock can occur if OS does not put restrictions on using resources. To avoid deadlock 4 conditions should happen: 1-no more than one process can hold a resource(mutual exclusion) 2-no process can hold a resource that it can't use until other resources are becoming available (resource holding) 3-OS can temporarily reallocate a resource (preemption) 4- no circular waiting (all processes and resources form a loop) -Starvation is the opposite of deadlock and it can occur if OS puts too many restrictions on using resources. ©Brooks/Cole, 2003 Figure 7-13 Deadlock ©Brooks/Cole, 2003 Figure 7-14 Deadlock on a bridge ©Brooks/Cole, 2003 Note: Deadlock occurs when the operating system does not put resource restrictions on processes. ©Brooks/Cole, 2003 Figure 7-15.a Starvation ©Brooks/Cole, 2003 Figure 7-15.b Starvation ©Brooks/Cole, 2003 Figure 7-15.c Starvation ©Brooks/Cole, 2003 Figure 7-16 Dining philosophers ©Brooks/Cole, 2003 Device Manager It is responsible for access to input/output devices and also for the efficient use of devices. In general device manager: -monitors constantly the status of every I/O device (free, in use, have problem,..) -Maintains a queue for each I/O device or one or more queues for similar I/O devices. -Controls the different polices for accessing I/O devices. It may use FIFO for one device and SJF for another ©Brooks/Cole, 2003 File Manager In general the responsibilities of file manager are: -control access to files (read/write/execute). - supervise the creation, deletion, modification of files -Control the naming of files -Supervise the storage of files (how and where they are stored) -Archiving and backups of files ©Brooks/Cole, 2003 7.4 POPULAR OPERATING SYSTEMS Windows, UNIX and Linux are popular OS. Each one has Its own user interface which is a program that accepts requests From users (processes) and interprets them for the rest of OS. In UNIX, LINUX , windows it is the SHELL or command inte ©Brooks/Cole, 2003