Interprocess: Pipeline, Message queue, signal, shared memory, socket
There are several ways to communicate between processes:
(1) Pipes: Pipelines can be used to communicate between affinity processes, allowing one process and another to communicate with a process that has a common ancestor to it.
(2) Named pipe (named pipe): The named pipe overcomes the limitation of the pipe without name, so that, in addition to having the functionality that the pipeline has, it allows for inter-process communication without affinity. Named pipes have corresponding file names in the file system. Named pipes are created by command Mkfifo or by system call Mkfifo.
(3) signal (Signal): signal is a more complex mode of communication, used to inform the receiving process of an event occurred, in addition to inter-process communication, the process can also send signals to the process itself; Linux in addition to supporting the UNIX early signal semantic function Sigal outside, It also supports the signal function sigaction that is semantically compliant with the POSIX.1 standard (in fact, the function is based on BSD, BSD in order to achieve a reliable signal mechanism, but also can unify the external interface, with the Sigaction function to re-implement the signal function).
(4) Message queue: Message Queuing is a linked table of messages, including POSIX Message Queuing system V Message Queuing. A process with sufficient permissions can add messages to the queue, and a process that is given Read permission can read the messages in the queue. Message queue overcomes the lack of signal carrying information, the pipeline can only carry the unformatted byte stream and the buffer size is limited.
(5) Shared memory: Allows multiple processes to access the same piece of memory space, is the fastest available IPC form. is designed for inefficient operation of other communication mechanisms. It is often used in conjunction with other communication mechanisms, such as semaphores, to achieve synchronization and mutual exclusion between processes.
(6) Memory mapping (mapped memories): Memory mapping allows any number of interprocess communication, and each process that uses the mechanism implements it by mapping a shared file to its own process address space.
(7) Semaphore (semaphore): primarily as a means of synchronization between processes and between different threads of the same process.
(8) Socket: A more general inter-process communication mechanism that can be used for inter-process communication between different machines. Originally developed by the BSD branch of the UNIX system, it can now be ported to other Unix-like systems: both Linux and System V variants support sockets.
Second, the method of thread communication
There are two main methods of thread communication:
Shared memory, Message Queuing, event objects, global variables
Process communication mode-thread communication mode