My views on inter-process communication

Source: Internet
Author: User

My views on inter-process communication

Written by: sccot: 2011-11-29

 

WindowsInter-process communication

Windows provides multiple mechanisms for applications to quickly and conveniently share data and information. These mechanisms include RPC, COM, OLE, DDE, message, clipboard, mail slot, pipeline, and socket. However, if multiple processes on the same machine communicate with each other, the above mechanisms are related to the shared memory. This is called a memory ing file on Windows.

This data sharing mechanism is implemented by ing two or more processes to the view of the same file ing object. This means that the process shares the same physical storage page. Therefore, when a process writes data to the view of the file ing object, other processes will immediately see changes in their views. However, for multiple processes to share the same file ing object, the names of the file ing objects used by all processes must be identical [1].

LinuxInter-process communication

The process communication methods in linux are basically inherited from the process communication methods on the Unix platform. The Bell Labs and BSD (Berkeley Software release center at the University of California Berkeley), which have contributed significantly to the development of Unix, have different emphasis on inter-process communication. The former improves and expands the inter-process communication methods in the early days of Unix to form a "system v ipc", and the communication process is limited to a single computer; the latter skips this restriction and forms a socket-based inter-process communication mechanism. Linux inherits the two.

Among them, the original Unix IPC includes: Pipeline, FIFO, signal; System v ipc includes: System V message queue, System V signal light, System V shared memory zone; Posix IPC includes: posix message queue, Posix signal lamp, and Posix shared memory zone. There are two points to explain: 1) due to the diversity of Unix versions, the Institute of electronic and electrical engineering (IEEE) developed an independent Unix standard, this new ANSI Unix standard is called the portable operating system interface (PSOIX) in the computer environment ). Most of the existing Unix and popular versions follow the POSIX standard, while Linux has followed the POSIX standard from the very beginning; 2) BSD is not involved in inter-process communication within a single machine (socket itself can be used for inter-process communication within a single machine ). In fact, many Unix versions of Single-host IPC have traces of BSD, such as the anonymous memory ing supported by 4.4BSD and the realization of reliable signal semantics by 4.3 + BSD [2].

In Linux, the inter-process communication mechanisms include pipelines, signals (messages on Windows), signal queues (actually message linked lists), shared memory, semaphores, and sockets.

Commonalities

From the above analysis, we can see that the two operating systems share a large number of inter-process communication mechanisms: pipelines, messages, shared memory, and sockets. Introduction:

Pipeline (Pipe) and famous Pipeline (named pipe): pipeline can be used for communications between kinship processes. Famous pipelines overcome the Pipe's no-name restrictions. Therefore, in addition to the functions of pipelines, it also allows communication between unrelated processes.

Signal or message: the Signal is a complex communication method used to notify the receiving process of an event. In addition to inter-process communication, the process can also send a Signal to the process itself.

Shared Memory: Allows multiple processes to access the same memory space. It is the fastest available IPC format. It is designed to reduce the running efficiency of other communication mechanisms. It is often used in conjunction with other communication mechanisms, such as semaphores, to achieve synchronization and mutual exclusion between processes.

Socket: a more general inter-process communication mechanism that can be used for inter-process communication between different machines.

Summary

A message queue is a chain table of messages. A Message Queue can only bear unformatted byte streams and the buffer size is limited because the signal carries less information; semaphores are mainly used for synchronization between processes and between different threads of the same process.

In my opinion, pipelines, clipboard, and shared memory are all based on shared memory. Messages, message queues, and sockets are all based on the message sending mechanism. They only refer to sending messages on the same machine or on the Network (sockets can be seen as sending messages on the network ). RPC, COM, OLE, and DDE generate a unified interface on the client and server. That is to say, these communication methods are actually equivalent to the protocols on the network. The Protocol for communication at the same layer no matter the next layer. It seems that the two layers have established a connection directly. The basic idea is to establish code similar to the stub code locally, and establish code similar to the pile code remotely for connection.

In the preceding communication mode, the clipboard and the anonymous pipeline can only implement communication between two processes on the same machine, while semaphores, messages, message queues, and shared memory can only communicate among multiple processes on the same machine; however, the named pipe, mail slot, and socket can not only implement communication between two processes on the same machine, but also cross-network communication. In addition, the Oil Slot and socket can implement one-to-many communication, while the named pipe can only communicate point-to-point and single communication. However, the disadvantage of the Oil Slot is that the data volume is small, usually less than 424 bytes, if the data volume is large, you can use the named pipe and socket method. In summary: in cross-network communication, sockets are undoubtedly the best communication method. This is perhaps the original intention of Berkeley to develop Sockets for network communication (traditional communication methods are not easy to use ).

Bibliography:

[1] windows core programming. Jeffrey Richter implements e nasarre

[2] advanced programming in UNIX environments. by W. Richard Steven s Stephen A. Rago

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.