Page 133 - DCAP103_Principle of operating system
P. 133

Principles of Operating Systems



                   Notes         In this unit, we describe methods that an operating system can use to prevent or deal with
                                 deadlocks. Most current operating systems do not provide deadlock-prevention facilities, but
                                 such features will probably be added soon. Deadlock problems can only become more common,
                                 given current trends, including larger numbers of processes, multi-threaded programs, many
                                 more resources within a system, and the emphasis on long-lived file and database servers rather
                                 than batch systems.


                                                Keep away your system from the deadlock condition for the best processing
                                                of the system.



                                 4.6.1 System Model
                                 A system consists of a finite number of resources to be distributed among a number of competing
                                 processes. The resources are partitioned into several types, each of which consists of some number
                                 of identical instances. Memory space, CPU cycles, files, and I/O devices (such as printers and
                                 tape drives) are examples of resource types. If a system has two CPUs, then the resource type
                                 CPU has two instances. Similarly, the resource type printer may have five instances. If a process
                                 requests an instance of a resource type, the allocation of any instance of the type will satisfy the
                                 request. If it will not, then the instances are not identical, and the resource type classes have not
                                 been defined properly. For example, a system may have two printers. These two printers may
                                 be defined to be in the same resource class if no one cares which printer prints which output.
                                 However, if one printer is on the ninth floor and the other is in the basement, then people on
                                 the ninth floor may not see both printers as equivalent, and separate resource classes may need
                                 to be defined for each printer. A process must request a resource before using it, and must
                                 release the resource after using it. A process may request as many resources as it requires to
                                 carry out its designated task. Obviously, the number of resources requested may not exceed
                                 the total number of resources available in the system. In other words, a process cannot request
                                 three printers if the system has only two. Under the normal mode of operation, a process may
                                 utilize a resource in only the following sequence:

                                    1.  Request: If the request cannot be granted immediately (for example, the resource is being
                                      used by another process), then the requesting process must wait until it can acquire the
                                      resource.
                                    2.  Use: The process can operate on the resource (for example, if the resource is a printer, the
                                      process can print on the printer).
                                    3.  Release: The process releases the resource. The request and release of resources are system
                                      calls. Examples are the request and release device, open and close file, and allocate and free
                                      memory system calls. Request and release of other resources can be accomplished through
                                      the waif and signal operations on semaphores. Therefore, for each use, the operating system
                                      checks to make sure that the using process has requested and been allocated the resource.
                                      A system table records whether each resource is free or allocated, and, if a resource is
                                      allocated, to which process. If a process requests a resource that is currently allocated to
                                      another process, it can be added to a queue of processes waiting for this resource.
                                 A set of processes is in a deadlock state when every process in the set is waiting for an event
                                 that can be caused only by another process in the set. The events with which we are mainly
                                 concerned  here  are  resource  acquisition  and  release.  The  resources  may  be  either  physical
                                 resources (for example, printers, tape drives, memory space, and CPU cycles) or logical resources
                                 (for example, files, semaphores, and monitors). However, other types of events may result in



        126                               LOVELY PROFESSIONAL UNIVERSITY
   128   129   130   131   132   133   134   135   136   137   138