Inter-process communication:
# pipe: A pipe is a half-duplex mode of communication in which data can only flow in one direction and can only be used between processes that have affinity. A process's affinity usually refers to a parent-child process relationship.
# famous pipe (named pipe): A well-known pipe is also a half-duplex mode of communication, but it allows communication between unrelated processes.
# semaphore (Semophore): Semaphore is a counter that can be used to control access to shared resources by multiple processes. It is often used as a locking mechanism to prevent a process from accessing the shared resource while other processes are accessing the resource. Therefore, it is primarily used as a means of synchronization between processes and between different threads within the same process.
# message Queue: Message Queuing is a linked list of messages, stored in the kernel and identified by message queue identifiers. Message Queuing overcomes the disadvantages of less signal transmission information, only unformatted byte stream, and limited buffer size.
# signal (sinal): A signal is a more sophisticated means of communication that notifies the receiving process that an event has occurred.
# Shared Memory: Shared memory is the mapping of memory that can be accessed by other processes, which is created by a process, but can be accessed by multiple processes. Shared memory is the fastest IPC approach and is specifically designed for low-efficiency operation of other interprocess communication modes. It is often used with other communication mechanisms, such as signal two, to achieve synchronization and communication between processes.
# Socket: Socket is also an inter-process communication mechanism, unlike other communication mechanisms, it can be used for different and inter-process communication.
Inter-thread communication:
# lock mechanism: Includes mutex, condition variable, read-write lock
* Mutexes provide an exclusive way to prevent data structures from being modified concurrently.
* Read-write locks allow multiple threads to read shared data concurrently, and write operations are mutually exclusive.
* Conditional variables can block processes in an atomic manner until a particular condition is true. The test of the condition is performed under the protection of the mutex. A condition variable is always used with a mutex.
# semaphore mechanism (Semaphore): Includes nameless thread semaphores and named thread semaphores
# signaling mechanism (Signal): signal processing between similar processes
Only the process needs communication, the thread of the same process share the address space, there is no need to communicate, but to do a synchronous/mutex mutex, the shared global variable is protected. Inter-process communication, whether the signal, pipe or shared memory is guaranteed by the operating system, is a system call.
Inter-process communication and inter-thread communication