Tuesday, March 3, 2009

Inter-Process Communication

Inter-Process Communication (IPC) is a set of techniques for the exchange of data among multiplethreads in one or more processes. Processes may be running on one or more computers connected by a network.

ِAlot Of Application use that mechanism which are :
  • Clipboard
  • COM
  • Data Copy
  • DDE
  • File Mapping
  • Mailslots
  • Pipes
  • RPC
  • Windows Sockets

  • Typically, we need to know if our application take advantage from that mechanism. there are several cases that we may need it. For example, a word processing application might act as a client in requesting a summary table of manufacturing costs from a spreadsheet application acting as a server.  we may need to distribute  heavy task into sub-tasks, that each process can handle each subtask independently.

    After you decide that your application would benefit from IPC, you must decide which of the available IPC methods to use. It is likely that an application will use several IPC mechanisms. The answers to these questions determine whether an application can benefit by using one or more IPC mechanisms.

    • Should the application be able to communicate with other applications running on other computers on a network, or is it sufficient for the application to communicate only with applications on the local computer?
    • Should the application be able to communicate with applications running on other computers that may be running under different operating systems (such as 16-bit Windows or UNIX)?
    • Should the user of the application have to choose the other applications with which the application communicates, or can the application implicitly find its cooperating partners?
    • Should the application communicate with many different applications in a general way, such as allowing cut-and-paste operations with any other application, or should its communications requirements be limited to a restricted set of interactions with specific other applications?
    • Is performance a critical aspect of the application? All IPC mechanisms include some amount of overhead.
    • Should the application be a GUI application or a console application? Some IPC mechanisms require a GUI application.


    Using Pipes for IPC

    There are two types of pipes for two-way communication: anonymous pipes and named pipes. Anonymous pipes enable related processes to transfer information to each other. Typically, an anonymous pipe is used for redirecting the standard input or output of a child process so that it can exchange data with its parent process. To exchange data in both directions (duplex operation), you must create two anonymous pipes. The parent process writes data to one pipe using its write handle, while the child process reads the data from that pipe using its read handle. Similarly, the child process writes data to the other pipe and the parent process reads from it. Anonymous pipes cannot be used over a network, nor can they be used between unrelated processes.


    Named pipes are used to transfer data between processes that are not related processes and between processes on different computers. Typically, a named-pipe server process creates a named pipe with a well-known name or a name that is to be communicated to its clients. A named-pipe client process that knows the name of the pipe can open its other end, subject to access restrictions specified by named-pipe server process. After both the server and client have connected to the pipe, they can exchange data by performing read and write operations on the pipe.


    No comments:

    Post a Comment