13.07.2015 Views

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

chapter 4RESOURCE DEADLOCKWe have dealt so far with two fundamental resources, time and space. Allocating theseresources is a matter of scheduling — that is, deciding which process should receivewhich resources at a given time. The time resource is granted by placing the process inthe ready list and then letting it execute. The space resource is granted by allowing partor all of the virtual space of the process to reside in main store.Both time and space are special. Time — the ability to execute — is held by onlyone process at a time (unless the computer is a multiprocessor). After the resource hasbeen held, it can be preempted and given for a while to another process. Space can beheld by many processes at once and may be preempted after a while. All regions of physicalspace are alike to the process. Every process requires both time and space.We will devote this chapter to allocation of resources that represent non-sharable,non-preemptable resources. Such resources represent extra facilities beyond space andtime, such as devices: files, printers, and tape drives. For example, a file might be restrictedso that only one process may use it at a time. Similarly, a printer or a tape drivemay be acquired by a process for a while and then given back. Finally, a process mayneed five tape drives during the course of its computation, but not all at once.Data structures within the kernel are often non-sharable, non-preemptableresources. For example, the kernel might have an array of context blocks. When a newprocess is started, a free context block must be allocated. As long as the process exists,that context block is neither shared nor preempted. Similarly, the file manager (which wediscuss in Chapter 5) might have an array of descriptors for open files. When a file isopened, a free descriptor is allocated, and must not be shared or preempted as long as thefile is in use. In a related vein, page frames that contain tied-down pages cannot beshared (unless processes are sharing pages) and are not preempted.Once a process has been granted such a resource, it is not possible to preempt theresource without injuring the process or the resource. For example, if the use of a file ispreempted, the process cannot assume that when it gets to use the file again, it will be inthe same state as before. The process has been injured and most likely should just quit.Even worse, the process may have left the file in an inconsistent state. For example, the121

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!