I. deadlock
In the operating system, several processes are executed concurrently, and they continuously apply for, use, and release system resources. Although the process coordination and communication mechanisms of the system control them, however, several processes may wait for the other party to release resources to continue running. Otherwise, the operation will be blocked. At this time, no one can release the resource without external factors, and no one can unblock the resource. According to this situation, the deadlock in the operating system is definedTwo or more processes in the system wait for the conditions that will never happen, and the system is stuck. This is a deadlock.
The cause of the deadlock is as follows:
(1) Insufficient system resources.
(2) The order in which the process is promoted is inappropriate.
(3) improper resource allocation.
If the system resources are sufficient, all process resource requests can be satisfied, and the possibility of deadlock is very low. Otherwise, a deadlock will occur due to competition for limited resources.
Second, the process may run in different order and speed, and may also lead to deadlocks.
Four Conditions for deadlock:
(1)Mutex: A resource can only be used by one process at a time.
(2)Request and persistence Conditions: When a process is blocked by requesting resources, it will not release the obtained resources.
(3)Non-deprivation conditions: Resources obtained by the process cannot be forcibly deprived before they are used.
(4)Cyclic wait Condition: A cyclical wait resource relationship is formed between several processes.
These four conditions are necessary for a deadlock. As long as a deadlock occurs in the system, these conditions must be met. As long as one of the above conditions is not met, no deadlock will occur.
Deadlock relief and prevention:
Understanding the cause of the deadlock, especially the four necessary conditions for the deadlock, can avoid, prevent and remove the deadlock as much as possible. Therefore, in terms of system design and process scheduling, pay attention to how to prevent these four necessary conditions from being established and how to determine reasonable resource allocation algorithms to avoid permanent occupation of system resources by processes. In addition, it is necessary to prevent the process from occupying resources while waiting. Therefore, reasonable planning should be made for resource allocation.
2. Process Communication Methods
(1)Pipeline (PIPE): A pipe is a half-duplex communication method. data can only flow in one direction and can only be used between unrelated processes. The kinship of a process usually refers to the parent-child process relationship.
(2)Named Pipe (Named Pipe): The named pipe is also a half-duplex communication method, but it allows communication between unrelated processes.
(3)Semaphores (semophore): A semaphore is a counter that can be used to control access to shared resources by multiple processes. It is often used as a lock mechanism to prevent other processes from accessing a shared resource. Therefore, it is mainly used between processes and between different threads in the same process.Synchronization Methods.
(4)Message Queue): A message queue is a linked list of messages stored in the kernel and identified by the Message Queue identifier. The message queue has overcome the disadvantages of few signal transmission information, the pipeline can only carry unformatted byte streams, and the limited buffer size.
(5) signal (Sinal): a signal is a complex communication method used to notify the receiving process that an event has occurred.
(6)Shared Memory): Shared memory is the memory mapped to a segment that can be accessed by other processes. The shared memory is created by one process, but can be accessed by multiple processes. Shared memory is the fastest IPC method. It is specially designed for the low efficiency of communication between other processes. It is often used with other communication mechanisms, such as signal two, to achieve synchronization and communication between processes.
(7)Socket): The Interprocess interface is also a communication mechanism between processes. Different from other communication mechanisms, it can be used for different and inter-process communication.
Reference: http://www.cnblogs.com/stoneJin/archive/2011/10/28/2227625.html
Deadlock and Process Communication