Interprocess Communication


Like UNIX, Windows has various forms of interprocess communication (IPC).The forms that are most familiar to UNIX developers are:

  • Process pipes

  • Named pipes

  • Message queues

  • Sockets

  • Memory-mapped files

  • Shared memory

Windows supports implementations of five of these; that is, all except message queues. For more information about message queues, see Message Queues laterin this chapter.

In addition to these there are two forms of IPC that are not part of the Win32 API. These are Message Queuing (also known as MSMQ) and COM+.

This section looks at how you convert UNIX code that uses the different forms of IPC. It also introduces new methods of IPC that are not available in UNIX, but may provide you with a better solution for your application s interprocess communication. The subject of sockets has been left until the next section.

Process Pipes

Process pipes are supported in Win32 by using the standard C runtime library.As discussed in the following sections, they are largely equivalent to processpipes in UNIX.

High-Level Popen Call

Three UNIX examples are considered in this section, and a slightly modified Win32 version of each has also been provided. Note that this text assumes the presence of the Uname .exe executable program on the Windows-based system. If your system does not contain this executable, these samples will not work and you will need to modify them to use an equivalent utility.

In the first example of process pipes, a process called uname is executed and passes the output of this process to standard output. As you review these examples, notice that the differences between the UNIX and Win32 implementations are the header files that are required and the function names for popen and pclose . The namesof these functions in Win32 are preceded by an underscore . The function syntax is the same and the behavior is largely compatible.

UNIX Example 1: Process Pipes
 #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> int main() {     FILE *read_fp;     char buffer[BUFSIZ + 1];     int chars_read;     memset(buffer, 


UNIX Application Migration Guide
Unix Application Migration Guide (Patterns & Practices)
ISBN: 0735618380
EAN: 2147483647
Year: 2003
Pages: 134

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net