IPC (Interprocess Communication)
Communication
- Exchange data between processes
- Can be used between threads of a process, but not necessary because threads can exchange information via shared global variables.
Synchronization:
- Synchronize actions of processes or threads
Types of communications
Types of synchronization
Data transfer:
- Require 2 data transfers between user memory and kernel memory
- For writing, one transfer from user memory to kernel memory
- For reading, another transfer from kernel memory to user memory.
- Byte stream
+ Via pipe, FIFO, datagram socket
+ Read operation: can read arbitrary number of bytes from IPC channel, regardless of size of blocks written by writer.
- Message
+ Via System V message queues, POSIX message queues and datagram socket.
+ Read operation: read a whole message, not possible to read multiple messages on a single read
Below is some examples.
Common illustration of data transfer
Parent-child using two PIPEs
Parent-child using two FIFOs
One server-multiple clients using FIFOs
Client-server using message queue
Shared memory
- Via System V shared memory, POSIX shared memory and memory mapping.
- Allow processes to exchange information by putting it to a region of memory that shared between processes.
- Don't require system calls or data transfer between user and kernel spaces, shared memory can support fast communication.
- However, share memory needs synchronization between processes.
Illustration of shared memory using semaphore.
Summary of IPC facilities
Persistence of IPC facilities
Reference
1. http://www.tldp.org/LDP/lpg/node7.html
2. https://www.cs.cf.ac.uk/Dave/C/
3. http://www.chandrashekar.info/articles/linux-system-programming/introduction-to-linux-ipc-mechanims.html
4. http://beej.us/guide/bgipc/output/html/singlepage/bgipc.html
5. Unix network programming, Vol.2
Không có nhận xét nào:
Đăng nhận xét