Communication is a more important concept. As long as there is more than one execution unit (concurrency), there is a possibility of communication.
Concurrency on Linux is mainly divided into multiple processes (tasks) and multithreading. Linux also provides multiple communication mechanisms to support the transfer of information between different processes or between different threads.
Communication methods mainly include pipeline, socket, message queue, shared memory, semaphore, mutex, signal (such as kill-0 detection process is normal) and so on.
Pipeline:
1. CGI technology. After the Deamon process receives a request, the child process is created to execute the CGI program, communicates with the child process through the nameless pipe, the parent process writes Fd[0], and the child process is responsible for writing fd[1]. The Deamon program then returns to the client by reading the output pipeline of the child process. (The limitation of communication is that processes must be related to each other)
2. Shell pipelines such as ps-ef |grep xxx
Sockets: Can be understood as the most common CS model. Multi-client and a server communication (such as Nginx use FCGI to execute PHP program, between FCGI and Nginx is through socket communication, nginx to 9000 port send request).
Message Queuing: Multiple processes can read and write message queues at the same time, often combining mutexes to achieve multi-threaded synchronization
Shared memory: The fastest means of communication, often combined with semaphores (the PV operation of the semaphore is guaranteed by the system kernel) to achieve multi-process synchronization
In communication, the more special is the parent-child process communication, because the child process inherits many things from the parent process, so in addition to the above mentioned means of communication, but also through the environment variable communication.
The communication mechanism of Linux