Thursday, October 11, 2012

Interprocess Communication in Unix



  • Pipes

The only real IPC facility available in early Unices was the ``pipe.''
Pipes are creating using the pipe system call
% prog1 | prog2
When a command like this is given to the shell, the shell creates a pipe before forking prog1 and prog2.
The ``write to'' end of the pipe is connected to prog1's stdout, while the ``read from'' end of the pipe is connected to prog2's stdin.
Now, output from prog1 is fed to prog2's input.


  • Named Pipes (FIFOs)

Closely related to the pipe is the ``named pipe,'' also called a FIFO. A FIFO is an IPC channel that is given a name in the file system space, using the mkfifo system call (there is also a mkfifo command that is just a wrapper around the mkfifo system call). Once a FIFO has been created processes can open it just like a file, and write to it or read from it. The only thing is, the data that is written is not actually written to a file; it's maintained in a buffer by the kernel.

Named pipes were a huge step forward, but still suffered from only being able to be used between two processes on a single system, not over a network.




  • Sockets

Conceptually, internet sockets on a Unix system look like a numbered array of interprocess communication channels -- so there is a socket 0, socket 1, socket 2, and so forth. They pretty much expect to be used in a client-server relationship; a daemon wishing to provide a service creates a socket and listens to it; a client program connects to the socket and makes requests. The daemon is also able to send messages back to the client.

http://www.cs.nmsu.edu/~pfeiffer/classes/574/notes/ipc.html

No comments:

Post a Comment