There are roughly the following types of inter-process communication under Linux:
- Pipes (including anonymous pipes for parent and child processes, named pipes)
- Shared memory
- Message queue
Socket can be used for local inter-process communication or remote inter-process, and is the most commonly used.
Pipeline – Anonymous Pipeline
It is generally created with pipe and communicates between father and son. Close the read/write pipeline in the parent process, and close the write/read pipeline in the child process.
Generally use mkfifo to create. If it is not stated that the pipe is non-blocking, then a pipe opened for reading will block until a process opens the FIFO for writing. Similarly, if a pipe opened for writing will block until a process opens this FIFO for reading.
A process can use kill to send a signal to another process.
shmget, shmat, shmctl, shmdt
Use shmget function to get a piece of memory, and use shmat to set it to allow this process to use this shared memory. Use shmdt to delete the memory block after use.
msgget, msgsnd, msgrcv, msgctl
The use steps are the same as above.