Thursday, February 17, 2011

Process communication

Process in a computer system should work together for the user use to run their program. Communication between processes involves changing or sharing data which run using its scheme.


Mutual Exclusion

·         The successful use of concurrency among processes requires
the ability to define critical sections and enforce mutual exclusion. This is fundamental for any concurrent processing scheme. Any facility or capability that is providing support for mutual exclusion should meet the following requirements:

·         Mutual exclusion must be enforced: Only one process at a time in allowed into its critical section among all proceses that have critical sections for the same resource or shred object.

·         A process that has in its no critical section must do so withot interfering with other processes.

·        It must not possible for a process requiring access to critical section to be delayed indefinitely; no deadlock or starvation can be allowed

·         When no process is in a critical section, any process that requests entry to its critical section must be permitted to enter without delay.

·         No assumptions are made about relative process speeds or number of processes.

·         A process remains inside its critical section for a finite time only.


Synchronization

·         Consider a situation where a producer process produces an item which is consumed by consumer process. The producer process can produce an item, while the consumer process is consuming another item. The two events, consumer process and producer process must be synchronized so that the consumer process does not consume any item that has not yet been produced. In this  situation consumer must wait until the item is produced.

·         If we assume hat there is an infinite size buffer which can store the new items produced, then the consumer may have to wait for new items only. However, if the buffer is bounded size then the consumer must wait if the buffer is empty and the producer must wait if the buffer is full.


Deadlock

·         A system will have certain resources, like memory space, CPU cycles, files, I/O devices (such as printers, tape, etc), which may be requested by processes.

·         The resources are partitioned into several types, each of which consists of some number of identical 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 resource type class has not been defined properly.
                
·         A process would request a resource it needs, and must release the resource after using it. And a process may request several resources which it may need for its accomplishment.

·         A process will use the resource in the sequence request use and release. The request and release of resources are system calls, like, request device, open file, close file and allocate memory.

·         To make sure that the using process has requested and been allocated the resource, the request and release of resources can accomplish through the wait and signal semaphores.


Dead-Lock Definition

·         A set of process is in a deadlock state when every process in the set is waiting for an event that can be caused by only another process in the set. The events in the set are acquisition and release.


Deadlock Characterization

·         A deadlock situation can arise if all the following four conditions are held simultaneously in a system. They are:

·         Mutual exclusion: at least there should be one resource in non-sharable mode and only one process at a time can use the resource. If a resource is occupied by a process and another process requests that resources the requesting process must be delayed until the resource has been released.

·         Hold and wait: There must exist a process that is holding at least one resource and is waiting to acquire additional resources that are currently being held by other processes.

·         No Pre-emption: Resources cannot be pre-empted that is a resource will be released only after the process holding it has completed its task.


Deadlock Avoidance

·         In this approach some additional information (about how resources will be requested) is used. With this knowledge (sequence of requesting and release of resources) suitable allocation strategy is arrived, avoiding deadlock.

·         One of the algorithms to avoid deadlock is that each process declare the maximum number of resources of each type it may need. With this information a prior, it is possible to construct an algorithm that ensures that system will never enter a deadlock state.

·         If a system does not have either deadlockprevention or a deadlock avoidance algorithm then a deadlock situation may occur. Under this situation, the system should have deadlock detection mechanism and strategy to recover from it.


Deadlock Avoidance

·         We explain this by assuming that resources in the system has only single instance. But we do is from resource allocation graph, derive another graph called as wait graph.

·         This wait graph is obtained from resource graph by removing the nodes of type resource and collapsing the appropriate edges.


 Recovery from deadlock

·         After detection of deadlock, several actions are possible. The possible action could be to let the operator deal with deadlock manually. Other method could be automatic recovery from deadlock. Deadlock could be broken by aborting one or more processes to break the circular-wait condition.

·         For recovery from deadlock, there is a need to terminate the process. One approach is to terminate all the processes involved in deadlock. This will result into complete loss of all processes and its results.

·         The other approach is to about process one by one at a time until the deadlock is eliminated however this method is time consuming. Also we need to identify which process should be terminated first. This may depend upon many factors like priority of a process, present state of the process.

·         The approach of eliminating deadlocks using resource pretemption, calls for successive pretemption of some resources from process and allocate them to other waiting process until the deadlock cycle is broken.

·         However the factors which need to be considered in this approach are: selection of a victim resource to be aborted, roll backing of the process for which the resource is pre-empted and to ensure that starvation will not occur.


Process Synchronization

Situation where the correctness of the computation perfomed by cooperating processes can be affected by the relative timing of the processes execution is called a race condition. To be considered correct, cooperating prosesed may not be subject to race condition. When cooperating processes run on a system with a single processor, concurrency is simulated by the processes sharing the CPU. The scheduling algorithm determines the relative timing of cooperating processes. The result may differ widely from an idealized perception of parallel execution. Not only is timing dependent on the scheduling algorithm used, it also depentdent on the system load created by other proceses on the system. On multiprocessor systems, there is no guarantee all processor work at equivalent speeds. Depending on which processes are allocated to which processors, timing can differ drastically.


12 comments: