Process Communication Mode in Windows

Source: Internet
Author: User
1. Process Communication The process is loaded into the memory and ready for execution.Program, Each process has a private virtual address spaceCode, Data and the system resources it can use(Such as files and Pipelines). Multi-Process/Multithreading isWindowsA basic feature of the operating system.Microsoft Win32Application Programming Interface(Application Programming Interface, API)Provides a large number of mechanisms to support data sharing and exchange between applications. These mechanisms are called inter-process communication.(Interprocess communication, IPC)Process communication refers to data sharing and data exchange between different processes.
This is becauseWin32 APIThere are many process communication methods. How to select an appropriate communication method becomes an important issue in application development.Win32Process Communication methods are analyzed and compared. 2 Process Communication Method 2.1 File ing
File ing(Memory-mapped files)The process can treat the file content as a memory block in the process address range. Therefore, the process does not need to use files.I/OOperation, you can read and modify the file content with simple pointer operations.
Win32 APIMultiple processes are allowed to access the same file ing object. Each process receives memory pointers in its own address space. By using these pointers, different processes can read or modify the file content to share data in the file.
There are three ways for an application to share a file ing object with multiple processes.
(1)Inheritance: the first process creates a file ing object. Its child process inherits the handle of the object.
(2)Naming file ing: when creating a file ing object, the first process can specify a name for this object.(Different from the file name). The second process can use this name to open the file ing object. In addition, the first process can also use some otherIPCMechanism(Famous pipelines, email slots, etc.)Pass the name to the second process.
(3)Handle replication: the first process creates a file ing object and then uses otherIPCMechanism(Famous pipelines, email slots, etc.)The object handle is passed to the second process. The second process copies the handle to obtain the access permission for the ing object of the file.
File ing is a very effective way to share data among multiple processes and provides better security. However, file ing can only be used between processes on the local machine and not on the network. Developers must also control the synchronization between processes.
2.2 Shared Memory
Win32 APIShared Memory(Shared memory)This is a special case of file ing. When creating a file ing object, the process uses0 xffffffffTo replace the file handle.(Handle)The corresponding file ing object accesses the memory from the file on the operating system page. Other processes can access the memory block by opening the file ing object. Because shared memory is implemented by file ing, it also has good security and can only run between processes on the same computer.
2.3 Anonymous Pipeline
MPs queue(PIPE)A communication channel with two endpoints: a process with one handle can communicate with a process with another handle. The pipeline can be one-way-one end is read-only, and the other end point is write-only. It can also be two-way. The two ends of a pipeline are both readable and writable.
Anonymous Pipeline(Anonymous pipe)Yes Between parent and child Processes , Or Two sub-processes of the same parent process A one-way pipeline with no name for data transmission between them. Generally, the parent process creates an MPS queue, and then the child process to communicate inherits the read endpoint handle or write endpoint handle of the channel, and then implements communication. The parent process can also create two or more sub-processes that inherit anonymous pipeline read and write handles. These sub-processes can communicate directly using pipelines without passing through the parent process.
The anonymous pipeline is the standard for sub-processes on a single machine.I/OAn Effective Method of redirection. It cannot be used online or between two unrelated processes.
2.4 Named Pipe
Named Pipe(Named Pipe)A one-way or two-way channel for communication between a server process and one or more client processes. Unlike an anonymous pipe, a named pipe can be used between unrelated processes and different computers. When the server creates a named pipe, a name is specified for it, any process can use this name to open the other end of the pipeline and communicate with the server process based on the given permissions.
The named pipeline provides a relatively simple programming interface, making it easier to transmit data over the network than to communicate with two processes on the same computer. However, it cannot communicate with multiple processes at the same time.
2.5 Email slot
Email slot(Mailslots)Provides one-way communication between processes. Any process can establish a mail slot as a mail slot server. Other processes, called mail slot customers, can send messages to the mail slot server process by the name of the mail slot. The incoming message is kept in the mail slot until the server process reads it. A process can be either a mail slot server or a mail slot customer , So you can create Multiple The mail slot implements inter-process Bidirectional Communication.
You can use the mail slot to send messages to the mail slots on the local computer, the mail slots on other computers, or the mail slots with the same name on all computers in the specified network area. The message length of broadcast communication cannot exceed 400 Bytes. The length of a non-broadcast message is limited by the maximum message length specified by the mail slot server.
The mail slot is similar to the named pipe, but it transmits data through unreliable Datagram(For exampleTCP/IPProtocolUDPPackage)Once a network error occurs, the message cannot be correctly received, while the named pipe transmits data based on reliable connections. However, the mail slot provides simplified programming interfaces and the ability to broadcast messages to all computers in the specified network area. Therefore, the mail slot is another option for applications to send and receive messages.
2.6 Clipboard
Clipboard(Clipped Board)The essence isWin32 APIA group of functions and messages used to transmit dataWindowsData sharing between applications provides an intermediary,WindowsCut created(Copy)-The pasting Mechanism provides a shortcut for different applications to share data of different formats. When a user performs a cut or copy operation in an application, the application puts the selected data in one or more formats on the clipboard. Then, any other application can pick up data from the clipboard and select a suitable format from the given format.
The clipboard is a very loose exchange medium that supports any data format. Each format is identified by an unsigned integer.(Predefined)Clipboard format. The value isWin32 APIDefined constant; can be used for non-standard formatsRegister clipboard formatThe function is registered as the new clipboard format. You only need to use the clipboard to exchange data in the same format or convert the data to a certain format. However, the clipboard can only beWindowsAnd cannot be used on the network.
2.7 Dynamic Data Exchange
Dynamic Data Exchange(DDE)It is a form of inter-process communication that exchanges data between applications that exist in the shared network. Applications can useDDEFor one-time data transmission, you can also dynamically exchange data between applications by sending update values when new data appears.
DDELike clipboard, standard data format is supported(Such as text and bitmap)And supports custom data formats. However, their data transmission mechanisms are different. One obvious difference is that clipboard operations are almost always used as a one-time response to user-specified operations-such as selecting from the menuPasteCommand. AlthoughDDEIt can also be started by the user, but it does not need further user intervention to continue to play its role.DDEThere are three data exchange methods:
(1)Cold Chain: data exchange is a one-time data transmission, the same as the clipboard.
(2)Warm link: when data is exchanged, the server notifies the customer, and then the customer must request new data.
(3)Hot chain: when data is exchanged, the server automatically sends data to the customer.
DDESwitching can happen between applications of different computers on a single machine or network. Developers can also define customDDEData format for special purposes between applicationsIPCThey have more closely coupled communication requirements. MostWindowsAll applications supportedDDE.
2.8 Object connection and embedding
Applications connect and embed objects(OLE)Technical Management compound document(Documents composed of multiple data formats),OleProvides services that make it easier for an application to call other applications for data editing. For example,OleSupported word processors can nest workbooks. When you want to edit workbooksOleThe workbook editor is automatically started. When you exit the workbook editor, the table is updated in the original word processor document. Here, the workbook editor becomes an extension of the word processor.DDEYou must start the workbook editor explicitly.
SameDDEThe same technology, most of which are based onWindowsAll applications supportedOleTechnology.
2.9 Dynamic Connection Library
Win32Dynamic Connection Library(DLL)Global data in can be calledDLLAll processes are shared, which opens up a new way for inter-process communication. Of course, pay attention to synchronization during access.
Although you can useDLLData sharing between processes, but from the perspective of data security, we do not advocate this method, using Shared Memory for access control Method Better Some.
2.10 Remote process call
Win32 APIProvided Remote Procedure Call(RPC)Allows applications to call functions remotely.RPCProcess Communication is as simple as function calling.RPCIt can be used between different processes on a single machine or on the network.
BecauseWin32 APIProvidedRPCObeyOSF-DCE (Open Software Foundation distributed computing environment)Standard. So passWin32 APICompiledRPCApplications can be supported with other operating systemsDecOfRPCApplication Communication. UseRPCDevelopers can build high-performance, tightly coupled distributed applications.
2.11 Netbios Function
Win32 APIProvideNetbiosFunctions are used to process low-level network control.IBM NetbiosSystem coding andWindows. Unless there are applications with special low-level network functional requirements, it is best not to use other applications.NetbiosFunction to perform inter-process communication.
2.12 sockets
Windows SocketsThe specification isU. C. BerkeleyUniversityBSD UNIXPopularSocketA set of interfaces defined for examplesWindowsNetwork programming interface. BesidesBerkeley socketIn addition to the original library functions, a groupWindowsSo that programmers can make full useWindowsProgram the message mechanism.
Now passSocketsMore and more network applications are used to implement process communication. The main reason is thatSocketsMore cross-platform than othersIPCThe Mechanism is much better.Winsock 2.0Not onlyTCP/IPAnd supports other protocols.(For exampleIPX).SocketsThe only drawback is that it supports underlying communication operations, which makes it inconvenient to transmit simple data between standalone processes.Wm_copydataMessages will be more appropriate.
2.13 wm_copydata Message
Wm_copydataIt is a very powerful but little-known message. When an application transmits data to another application, the sender only needs to callSendmessageFunction, the parameter is the destination window handle, the starting address of the data to be transferred,Wm_copydataMessage. The receiver only needs to process messages as other messages are processed.Wm_copy dataMessage, so that both parties can share data.
Wm_copydataIs a very simple method, it is actually through File ing . Its disadvantage is that it is not flexible and can only be usedWindowsPlatform Standalone Environment .
Related Article

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.