Next: Pipes
Inter-process Communication (IPC)
In order for processes to ceoperate on some task they must be able to communicate with each other. Linux supports many different forms of inter-process communication (IPC) mechanism, each of which has advantages and disadvantages in particular circumstances. The purpose of this chapter is to review the most useful IPC mechanisms so that you can make sensible choices when you come to write co-operating concurrent processes.
The simplest way to communicate values between processes is via a file. One process writes to the file and another process reads from it. This is a surprisingly simple mechanism which has several advantages:
- It will allow any pair of processes with access permission to the file to use it for communication.
- It can allow the transfer of very large amounts of data between processes.
Despite these advantages, the use of files as a major IPC mechanism has two big drawbacks:
- In order to make sure that the reader has the opportunity to see all the data sent to it, the writer must only add new data to the end of the file. This means the file can grow very large for long lived processes.
- If the reader performs its task faster than the writer then it will frequently catch up with the writer and have nothing to read. This means that the reader will constantly be reading end-of-file and not be able to tell whether this is because the writer has finished and closed the file, or the writer is still computing values to pass to the reader and there will be more to follow.
The simplest IPC mechanism which overcomes the problems inherent in the use of files is the pipe.
Next: Pipes