Interprocess Communication – Mac, Windows, Linux

This is a work in progress.

IPC on Mac

Here are the options

  • Sockets
  • Mach ports
  • Pipes
  • FIFOs
  • Shared memory

There is also XPC, but this requires you to refactor your code into XPC services, so this isn’t really IPC as generally talked about.

<more here>

IPC on Windows

Here are the options

  • Data Copy (WM_COPYDATA)
  • File mapping
  • Named shared memory
  • Pipes
  • RPC
  • Windows Sockets

This ignores several older techniques such as Clipboard, COM, or DDE. Mailslots are technically IPC, but generally used for broadcast and best-effort instead of point-to-point guaranteed communication.

Data Copy

This only works between processes on the same machine.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms648710(v=vs.85).aspx

File Mapping

This only works between processes on the same machine.

Uses CreateFileMapping and MapViewOfFile to map a file to memory, then read and write to memory to perform the IPC operations. This can be fairly efficient, although the processes will need to coordinate reads and writes. The downside is that this will result in file writes, reducing efficiency. Generally, you would avoid doing this in favor of the named shared memory variant.

http://msdn.microsoft.com/en-us/library/windows/desktop/aa366878(v=vs.85).aspx

Named Shared Memory

This only works between processes on the same machine.

This is a special variant of File Mapping that creates file mapping objects referencing the system paging file. The advantage here is that no actual file is needed. This is the closest equivalent on Windows to shared memory as found on Linux or Mac.

http://msdn.microsoft.com/en-us/library/windows/desktop/aa366551(v=vs.85).aspx

Pipes

Anonymous pipes can only be between processes running on the same machine, and typically between a parent process and a child process. However, it is possible to send the pipe handles to another process by a separate IPC mechanism (such as shared memory).

Named pipes can be used between arbitrary processes on the same or different machines.

http://msdn.microsoft.com/en-us/library/windows/desktop/aa365780(v=vs.85).aspx

IPC on Linux

<coming>

Reference

https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/OSX_Technology_Overview/SystemTechnology/SystemTechnology.html

http://www.puredarwin.org/curious/ipc

http://stackoverflow.com/questions/2846337/best-way-to-do-interprocess-communication-on-mac-os-x

http://afewguyscoding.com/2012/07/ipc-easy-introducing-xpc-nsxpcconnection/

https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingXPCServices.html#//apple_ref/doc/uid/10000172i-SW6

https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/OSX_Technology_Overview/SystemTechnology/SystemTechnology.html

http://www.cocoawithlove.com/2009/02/interprocess-communication-snooping.html

http://my.safaribooksonline.com/book/operating-systems-and-server-administration/mac-os-x/0321278542/interprocess-communication/ch09lev1sec3