Interprocess Communication


Interix supports all the various forms of Interprocess Communication (IPC). The forms most familiar to UNIX developers are discussed in the following sections:

  • Ordinary or anonymous pipes

  • Named pipes

  • Message queues

  • System V IPC mechanisms

Ordinary (Anonymous) Pipes

Process pipes are supported under Interix by using the standard C runtime library. Interix supports all the pipe function calls, including popen , pclose , and pipe . There is no need to change any references to these calls in your code.

Pipes are frequently used between UNIX processes to connect the standard output file descriptor of one process to the standard input file descriptor of a second process, causing the results of the first program to be treated as the input data of the second. This sequence of commands is called a pipeline .

This mechanism works unchanged under Interix when connecting Interix processes. It is possible to use this same mechanism to connect an Interix process to a Win32 process that it creates. In nearly all cases, everything works as is without any change. Problems with using pipes to communicate between Interix and Win32 processes generally fall into two categories:

  • Line termination character. Interix defines a line as ending with the \n character; Win32 defines lines as ending with the \r\n sequence. Some applications are sensitive to the precise line termination sequence. Use the flip command in the pipe to change line termination as necessary.

  • End Of File (EOF) handling when attempting serial use of a pipe. After a Win32 process has closed a pipe it is writing to, it is not possible for an Interix application to serially use that pipe. For example, this command will display only the contents of file1 :

     (cmd.exe /c type file1; cat file2)  cat 

    By introducing a second pipeline using the cat32 utility, this problem canbe solved using this command:

     (cmd.exe /c type file1; cat file2  cat32)  cat 

Named Pipes (FIFOs)

Interix also supports named pipes. These are also referred to as First in First Out (FIFO). A named pipe is a special type of pipe that is created in the file system (with the mknod or mkfifo function calls or command line programs), but behaves like a process pipe.

Interix supports the two function calls for creating a named pipe, mknod and mkfifo . If possible, use mkfifo for making FIFO special files because it is more portable.

Again, it is not necessary to modify code that uses these functions for it to compile under Interix.

These named pipes are distinct from, and not interoperable with, the identically named Win32 interprocess communication mechanism. The only way to useWin32 named pipes to communicate between Interix and Win32 processes is through ordinary pipes, as described earlier.

For examples of UNIX code that ports to Interix without modification, see the following sections in Chapter 9, Win32 Code Conversion :

  • Appendix 9.8: Creating a Named Pipe

  • Appendix 9.9: Opening a FIFO

  • Appendix 9.10: Interprocess Communication with FIFOs

Message Queues

Message queues are very similar to named pipes, but there is no need to open and close pipes. Interix supports all the message queue routines, msgctl , msgget , msgrcv , and msgsnd . Code that uses these functions does not need to be modified.

System V IPC Mechanisms

Interix includes support for the System V IPC shared memory and semaphore mechanisms. (For more information, see the discussion in Memory Management earlier in this chapter.) Code that uses these mechanisms should not need changes to compile under Interix.

For an example of UNIX code that ports to Interix without modification, see Memory-Mapped Files in Chapter 9, Win32 Code Conversion.

For an example of UNIX shared memory code that ports to Interix without modification, see Shared Memory in Chapter 9, Win32 Code Conversion.




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