Communications of Processes
There are 5 ways for processes to communicate with each other.
1. Environment Variable/File Descriptor
The child process inherits the copies of many kinds of resources of its parent. But it is unidirectional and one-off. The changes of these copies will not affect the parent process, and vice versa.
2. Command-line Argument
The parent process uses exec() or another function of its family to pass the values to its child process. It is also unidirectional, but not one-off. It can be regarded as a kind of function call, and can be used as many times as you need.
3. Pipe
This method usually uses a file or some other data structure as the pipe so that two processes can write data to the pipe and read data from it. It is bidirectional and any process who knows that pipe can use it.
4. Shared Memory
It is a block of memory which is outside of the two communicating processes. It can be accessed by any process as long as it is authorized.
5. DDE (Dynamic Data Exchange)
Its basic model is client/server. It uses the message system, which is provided by the operating system, to do the communication. It consists of 4 main components, they are DDE server, DDE client, the links between server and client, and the shared memory.
Communications of Threads
Here, the techniques of communication between the threads in the same process are discussed. There are commonly 3 ways to do the ITC (InterThread Communication).
1. Global variable
It can be a variable or a data structure, which is declared as global. It can be accessed by any thread in that process. Any change of that variable a thread makes is immediately known by all the other ones. One thing to be concerned is synchronization of these simultaneous threads' access should be guaranteed.
2. Argument
It works in the way like what it does in IPC.
3. File Handler
It points to a file, which is used as a shared memory. Still, how to make those threads synchronized and cooperate correctly is focused on.