IPC inter-process communication

Source: Internet
Author: User

Inter-process communication
(IPC
,Inter-process communication

) Indicates at least two processes.
Or thread
Some techniques or methods for transmitting data or signals between them. Process is a computer system
The minimum unit for allocating resources. Each process has a part of its own independent system resources, which are isolated from each other. In order to allow different processes to access resources and coordinate each other, inter-process communication is available. These processes
It can run on the same computer or on different computers connected to the network.
Inter-process communication technologies include message transmission, synchronization, shared memory, and Remote Process calling.
.
IPC is a standard UNIX
Communication mechanism.

Currently, the following methods are available for inter-process communication:

  • Named and anonymous Pipelines

    Pipe

  • Credit criteria
    Semaphore
  • Mutex

    Mutex

  • Shared Memory

    Shared Memory

  • Message Queue

    Message Queue

  • File System
  • CORBA
  • D-bus

The following methods apply only to specific operating systems
Platform or specific programming language:

Microsoft
Windows
:

  • Com

  • COM +
  • DCOM
  • Ole

Some people think that this can also be considered a way of inter-process communication:

  • Clipboard

    Clipboard

  • Person
    Itself

**************************************** **************************************** ***************

Inter-process communication (IPC)
Four different technologies:
1. message transmission (pipelines, FIFO, POSIX, and System V message queues)
2.
Synchronization (mutex lock, condition variable, read/write lock, file and record lock, POSIX and System V signal light)
3.
Shared Memory area (anonymous shared memory area, famous POSIX shared memory area, famous System V shared memory area)
4. process call (Solaris gate, Sun RPC)

Message queues and process calls are often used independently, that is, they generally provide their own synchronization mechanisms. on the contrary, the shared memory area usually needs some synchronization form provided by the application to work normally. which IPC should be used to solve a specific problem? There is no simple determination. We should gradually familiarize ourselves with the mechanisms provided by various IPC forms, and then compare their features according to the requirements of specific applications.

The following four prerequisites must be taken into account:
1.
The Internet is not connected. IPC is applicable to processes or threads on a single host. if applications may be distributed across multiple hosts, you should consider using sockets instead of IPC to simplify the future transfer to networked applications.

2. Portability.
3. Performance: run the test program in a specific development environment to compare the performance differences of several IPC types.
4.
Real-time scheduling. If this feature is required and the system in use supports the POSIX real-time scheduling option, use the POSIX message transmission and synchronization functions.

Main differences between various IPC types:
1. Pipelines and FIFO are byte streams without message boundaries. POSIX messages and System
A v message has a record boundary maintained from the sender to the receiver (eg. TCP is a byte stream without record boundary, and UDP provides a message with record boundary ).
2.
When a message is placed in an empty queue, the POSIX Message Queue can send a signal to a process, or start a new thread. System V does not provide similar notifications.
3.
Pipelines and FIFO data bytes are FIFO. POSIX messages and System
A v message has the priority assigned by the sender. When reading messages from a POSIX message queue, messages with the highest priority are first returned.
When reading a message queue, the reader can require messages of any priority.
4. In many message transmission technologies-pipelines, FIFO, POSIX message queues and System
In the V message queue, only read and write functions can be called from a signal processing program (applicable to pipelines and FIFO ).

When comparing different forms of message transmission, we are interested in two measurement scales:
1.
Bandwidth: the speed at which data is transferred through the IPC channel. to measure this value, we send large amounts of data (Millions of bytes) from one process to another ). we also measure this value for I/O operations of different sizes (such as write and read operations of pipelines and FIFO, we look forward to discovering the law that the bandwidth will increase with the increase of the data volume for each I/O operation.

2.
Latency: the time it takes for a small IPC message to return from a process to a process. we measure the time (round-trip time) from a process to a process with only one byte message)

In the real world, bandwidth tells us how long it takes to send large pieces of data through an IPC channel. However, IPC is also used to transmit small control information, the time required by the system to process these small messages is provided by delay. both numbers are important.

**************************************** **************************************** ***************

11 methods of inter-process communication

Using named objects
Waiting for multiple objects
Waiting in a message loop
Using mutex objects
Using semaphore objects
Using Event objects
Using critical section objects
Using timer queues
Using waitable timer objects
Createfilemapping
I think it is more convenient to use event.

11 methods of inter-process communication implementation (IPC)

A process is usually defined as an instance of a running program. It consists of two parts:
One is the kernel object used by the operating system to manage processes. The kernel object is also used by the system to store process statistics.
The other is the address space, which contains the code and data of all executable modules or DLL modules. It also contains dynamically allocated space. Such as thread stack and heap allocation space. Each process is assigned its own virtual address space. When a thread in the process is running, the thread can access the memory of the process that only belongs to it. Memory of other processes is hidden and cannot be accessed by running threads.
In order to communicate between two processes, the following methods can be used for reference:
0. Clipboard clipboard: Commonly Used in the 16-bit era, supported by cwnd
1. The Windows message standard and the dedicated wm_copydata message sendmessage () receiver must have a window
2. Use shared memory (shared memory)
A. Set a shared memory area
Handle createfilemapping (handle, lpsecurity_attributes, DWORD, lpcstr)
Generate a file-mapping core object
Lpvoid mapviewoffile (
Handle hfilemappingobject,
DWORD dwdesiredacess,
DWORD dwfileoffsethigh,
DWORD dwfileoffsetlow,
DWORD dwnumberofbytestomap
);
Get the shared memory pointer
B. Find out the shared memory
It is determined that this memory should be presented in the form of peer to peer
Each process must have the same capability to generate shared memory and initialize it. Each process
Createfilemapping () should be called, and then getlasterror () should be called. If
The error code is error_already_exists, so the process can assume that the shared memory region has been opened and initialized by other processes. Otherwise, the process can reasonably think that it is ranked first, then, initialize the shared memory.
Still use the Client/Server Architecture
Only the server process should generate and initialize the shared memory. All processes should use
Handle openfilemapping (DWORD dwdesiredaccess,
Bool binherithandle,
Lptstr lpname );
Call mapviewoffile () to obtain the shared memory pointer.
C. synchronous processing (mutex)
D. Cleaning up bool unmapviewoffile (lpcvoid lpbaseaddress );
Closehandle ()
3. Dynamic Data Exchange (DDE) enables inter-application transfer by maintaining global memory allocation
The method is to manually place a large amount of data in the global memory, and then use the window message to pass the memory pointer. this is the method used in the 16-bit win era, because there is no global or local memory in Win32, and currently there is only one kind of memory: virtual memory.
4. Message Pipeline)
This channel is used to set a permanent communication channel between applications.
Access a flat file to read and write data.
Anonymous pipeline (anonymous pipes)
One-way flow, and can only flow between processes on the same computer.
Named Pipes)
Two-way, cross-network, any process can easily grasp, the data put into the pipeline has a fixed format, and the use of readfile () can only read a multiple of this size.
Can be used in I/O Completion Ports
5. mailslots)
Broadcast Communication, a new method provided in 32 systems, supports data exchange between different hosts, and only supports mail slot customers in Win9x
6. Windows Socket)
It has all the functions of the message pipeline, but complies with a set of communication standards so that applications on different operating systems can communicate with each other.
7. Internet communication: allows an application to upload or download files from an Internet address.
8. RPC: Remote Procedure Call, rarely used, because it is not compatible with Unix RPC.
9. Serial/parallel communication (Serial/parallel communication)
It allows applications to communicate with other applications through serial or parallel ports.
10. COM/DCOM
Data exchange between processes is performed through the proxy stubs of the com system, but data can only be transferred when calling interface functions. data can be transferred between different hosts through DCOM.

**************************************** **************************************** ***************

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.