* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download NET201_Lecture3-22
Survey
Document related concepts
Transcript
Virtual Memory Networks and Communication Department Virtual memory Demand paging and demand segmentation mean that, when a program is being executed, part of the program is in memory and part is on disk. This means that, for example, a memory size of 10 MB can execute 10 programs, each of size 3 MB, for a total of 30 MB. At any moment, 10 MB of the 10 programs are in memory and 20 MB are on disk. There is therefore an actual memory size of 10 MB, but a virtual memory size of 30 MB Networks and Communication Department Virtual memory (Cont.) Virtual memory, which implies demand paging, demand segmentation or both, is used in almost all operating systems today. Figure below shows the concept. Networks and Communication Department OS Components- Process manager A second function of an operating system is process management, but before discussing this concept, we need to define some terms. A program is a non-active set of instructions stored on disk. 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. A process is a program in execution. It is a program that has started but has not finished. Networks and Communication Department State diagrams The relationship between a program, a job and a process becomes clearer if we consider how a program becomes a job and how a job becomes a process. This can be illustrated with a state diagram that shows the different states of each of these entities. Networks and Communication Department State diagrams (Cont.) Figure shows a State diagram with boundaries between program, job and process Networks and Communication Department State diagrams (Cont.) A program becomes a job when selected by the operating system and brought to the hold state It remains in this state until it can be loaded into memory When there is memory space available to load the program totally or partially, the job moves to the ready state. It now becomes a process It remains in memory and in this state until the CPU can execute it, moving it to the running state at this time When in the running state, one of three things can happen: The process executes until it needs I/O resources, it goes into the waiting state The process exhausts its allocated time slot, it goes into the ready state The process terminates, it goes into the terminated state Networks and Communication Department Schedulers To move a job or process from one state to another, The process manager uses two schedulers The job scheduler The process scheduler Networks and Communication Department Schedulers (Cont.) Job scheduler: Moves a job from the hold state to the ready state or from the running state to the terminated state (Figure shows job scheduler) Networks and Communication Department Schedulers (Cont.) Process scheduler: Moves a process between the running, waiting, and ready states many times before it goes to the terminated state and is no longer a process As shown in the figure below Networks and Communication Department Queuing In reality, there are many jobs and many processes competing with each other for computer resources. Networks and Communication Department Queuing To handle multiple processes and jobs, the process manager uses queues (waiting lists). A job control block or process control block is associated with each job or process. This is a block of memory that stores information about that job or process. The process manager stores the job or process control block in the queues instead of the job or process itself. Networks and Communication Department Queuing (Cont.) Figure shows the circulation of jobs and processes through three queues ( the job queue, the ready queue , and the I/O queue) Networks and Communication Department Queuing (Cont.) The job queue holds the jobs that are waiting for memory The ready queue holds the processes that are in memory, ready to be run and waiting for the CPU The I/O queue holds the processes that are waiting for an I/O device (one queue for each I/O device) Networks and Communication Department Selecting next job or process The process manager can have different policies for selecting the next job or process from a queue: It could be first in first out (FIFO), shortest length first, highest priority first, and so on Networks and Communication Department Process synchronization The whole idea behind process management is to synchronize different processes with different resources. Whenever resources can be used by more than one user (or process, in this case), we can have two problematic situations: deadlock and starvation. Networks and Communication Department Deadlock on a narrow bridge Networks and Communication Department Deadlock Deadlock occurs when the operating system does not put resource restrictions on processes. There are four necessary conditions for deadlock to occur: Mutual exclusion only one process can hold a resource Resource holding A process holds a resource even though it cannot use it until other resources are available No preemption The OS cannot temporarily reallocate a resource Circular waiting All processes and resources involved form a loop Networks and Communication Department Deadlock example Assume that there are two processes, A and B Process A is holding File 1, and it has requested File 2 and cannot release File 1 until it acquires File 2 Process B is holding File 2, and it has requested File 1 and cannot release File 2 until it acquires File 1 Files in most system are not sharable If there is no provision in this situation to force a process to release a file, deadlock is created (as shown in figure below) Networks and Communication Department Deadlock example (Cont.) Networks and Communication Department How the system preventing deadlock? One solution is not to allow a process to start running until the required resources are free, but this creates another problem (Starvation) The second solution is: do not allow one of deadlock conditions to happen (i.e. limit the time a process can hold a resource) Networks and Communication Department The dining philosophers problem Networks and Communication Department Starvation Starvation is the opposite of deadlock. It can happen when the operating system puts too many resource restrictions on a process. Networks and Communication Department Starvation example For example, imagine an operating system that specifies that a process must have possession of its required resources before it can be run In Figure below, Imagine that process A needs two files, File1 and File2 File1 is being used by process B and File2 is being used by process E Process B terminates and releases File1 Process C, which needs only File1, is allowed to run Process E terminates and releases File2 Process D, which needs only File2, is allowed to run Networks and Communication Department Starvation example (Cont.) Networks and Communication Department OS Components- Device manager The device manager, or input/output manager, is responsible for access to input/ output devices. There are limitations on the number and speed of input/output devices in a computer system. The device manager is responsible for the efficient use of input/output devices Networks and Communication Department Device manager responsibilities The device manager monitors every input/output device constantly to ensure that the device is functioning properly. The device manager maintains a queue for each input/output device or one or more queues for similar input/output devices. The device manager controls the different policies for accessing input/output devices. i.e. it may use FIFO for one device and shortest length first for another Networks and Communication Department OS Components- File manager Operating systems today use a file manager to control access to files. The responsibilities of a file manager: Controls access to files. The type of access can vary (read, write, execute) Supervises the creation, deletion, and modification of files. Controls the naming of files. Supervises the storage of files. ( how, where,.. etc) is responsible for archiving and backups. Networks and Communication Department Any Questions ? 29 Networks and Communication Department References Behrouz Forouzan and Firouz Mosharraf, “Foundations of computer science”, Second edition, chapter7, pp. 188-203 Networks and Communication Department