Linux IPC Simple Summary

Source: Internet
Author: User

# # #Linux ipc###
---------------

# #消息传递 # #

- Signal: Non-affinity, less information, only control information rather than data information

- Pipeline: To relatives, no boundary byte stream, first-out, consumed on the lost, no snooping function Msg_peek

- FIFO: Non-affinity, no boundary byte stream, FIFO, consumption is gone, no snooping function Msg_peek

- Socket: Non-affinity, marginal, less efficient

- Unix Sockets: Non-affinity, marginal, more efficient than sockets, less efficient than shared memory

- Message Queuing: No affinity, there are boundaries, less efficient than shared memory, priority, consumption is lost, no snooping function Msg_peek

The difference between POSIX and System V two, POSIX Message Queuing and System V Message Queuing: POSIX Message Queuing supports notify,
each time the highest priority message is taken, POSIX can correspond to a file (persisted with the file system) by Fstat the
The file gets the message queue information, and System V can specify which priority message to take each time, which is described by the ipc_perm structure.

- Shared memory

the most efficient, the disadvantage is that you need to handle synchronization
Anonymous shared memory: System V and POSIX open with Shm_open are anonymous and persist with the kernel
Well- known shared memory: POSIX opened with open famous, can continue with the file system, with the file continued
POSIX can be expanded while it is in use, and System V is set up at the time of creation.


# #同步机制 # #

- Mutex: Only two states (the semaphore has a >2 state), unlock only a locked process complete (semaphore not used)

- Condition variables: If no thread is in the condition variable, then the signal is lost (the semaphore is not lost because there is a state associated with it)

- Read-write Lock: Different from the mutex, the reading lock can be added multiple times, the write lock can only be added once. Pay attention to the problem of read and write hunger.

- Semaphore: SYSTEMV is anonymous, POSIX has both famous and anonymous. Well-known can always be shared between different processes, anonymous requires a semaphore in shared memory. The POSIX-known signal can be persisted with the file, which is not unlocked, and the next time the kernel or process is started is unlocked.

- Record lockout: Mutex (condition variable + read-write lock) can only be used between processes that are defined by the same process or lock in shared memory. Record locking can be used for processes that are completely irrelevant. Sub-advisory records are locked and mandatory records are locked. The exhortation to write the lock is not affected by the read, and the read lock is not affected by the write; a mandatory lock causes the kernel to check each read and write request to verify that its operation does not interfere with a lock held by a process. For a typical blocking descriptor, a read or write that conflicts with a mandatory lock will put the calling process to sleep until the lock is released. For non-blocking descriptors, a read or write that conflicts with a mandatory lock causes them to return a eagain error. Record locks are not explicitly unlocked at the end of the process and the kernel is unlocked. System V is optional for this feature, while the others do not.


# #IPC的优缺点 # # #

- Pipe: Data can only flow in one direction and can only be used between processes that have affinity. The advantage is convenience, when fork a child process, the parent process often uses pipe to get the output of the child process.

- A well-known pipe (named pipe), also known as FIFO: a well-known pipe is also half-duplex, but it allows communication between unrelated processes.

- Message Queuing: Message Queuing overcomes the disadvantages of less signal delivery information, a pipeline that can only host unformatted byte streams, and limited buffer size. Communication between the two processes can be completely unrelated to the process, the message does not have to be read in FIFO order, or can be read by the type of the message. More advantages than FIFO. But it's rare to see useful message queues.

- Shared memory: The advantage is fast, the disadvantage is that programmers need to do synchronization, the requirements of the programmer is relatively high. Mmap (POSIX) can map files, whereas shm* can only map memory.



"Original" Reproduced please specify: http://blog.csdn.net/huangkq1989/

Linux IPC Simple Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.