Unix Application Migration Guide (Patterns & Practices)

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

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:

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 :

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.

Категории