One year ago I wrote a survey about this topic. Here is a part of it:
2 Unix IPC mechanisms
Unix IPC mechanisms include:
- Unix signals.
- Unix pipes.
- Unix domain sockets.
At the same time Unix System-V IPC mechanisms are not included in Android.
Bionic intentionally does not provide support for System-V IPCs mechanisms, like the
ones provided by semget(), shmget(), msgget(). The reason for this is to avoid denial-
of-service [11].
2.1 Unix signals
One of the best explanations how unix signals work we can find in wikipedia: “A
signal is a limited form of inter-process communication used in Unix, Unix-like, and
other POSIX-compliant operating systems. Essentially it is an asynchronous notifica-
tion sent to a process in order to notify it of an event that occurred. When a signal is
sent to a process, the operating system interrupts the process’s normal flow of execu-
tion. Execution can be interrupted during any non-atomic instruction. If the process has
previously registered a signal handler, that routine is executed. Otherwise the default
signal handler is executed.”
It seems that unix signals are rearly used in Android programming. Moreover,
some signals have been disabled in debug mode. However, it is a possible IPC
mechanism.
2.2 Unix pipes
Pipe is a communication mechanism that allows to connect directly the output stream
of one process with the input stread of another process. There are two types of unix
pipes: named pipes and unnamed pipes. It seems that in Android programming only
named pipes are used. In this case two processes interact using a special file that
connects the output and input. It should be mentioned that pipe is one-direction way
of communication, i.e. one process is always reader and the second is always writer.
The communication file has to be created on Linux filesystem, because sdcard’s FAT32
does not allow to create pipe. Here is an example how a named unix pipe can be created
and used in Android (In Russian). The source code for this example can be found here.
2.3 Unix domain sockets
Unix domain sockets, on the contrary of unix pipes, allow to tranfer information in
both ways: from server to client and from client to server. Unix domain sockets
and unix pipes use file system as address name space. That means that server and
client use special file to establish communication. Considering Android there are two
classes that are used to program unix domain sockets: LocalServerSocket and
LocalSocket. All the implementation can be built around these two classes and it is
not required to use native code to make a unix domain socket. A simple example how
to use unix domain sockets is shown here.
[11] Android ndk documentation. NDK documentation for android-ndk-r6b