UNIX Domain Sockets
UNIX Domain sockets (UDS), also called IPC sockets, are similar to FIFOs except that they are duplexed–communication is bidirectional. UDS are similar to network sockets, which we will discuss later in this module, except that they are bound to a path within the file system and are used only for local communication between processes on the same host. They can also be used for some special purposes like sending duplicates of open file descriptors to other processes, which are unique this particular type of socket.
There are three basic types of sockets. Stream-oriented sockets behave just like bidirectional FIFOs, and can be used for sending streams of bytes in either direction, which is analogous to the TCP internet protocol. Datagram-oriented sockets preserve message boundaries, but messages may be reordered or dropped, which is analogous to the UDP internet protocol. Finally, sequenced-packet sockets preserve message boundaries and deliver messages in the order they were sent, which is analogous to the SCTP internet protocol.
UDS are much more powerful than FIFOs and are commonly used for a variety of purposes. For example, many system services create and communicate over UDS, allowing other services and user-space programs to manage those services or retrieve information from them. Many user-space GUI applications also expose a UDS-based API for programmatic control and communication. Additionally, message-based UDS are frequently used to implement things like job queues, with multiple writers dispatching jobs, and multiple readers in a work queue that process jobs. The message-based protocol prevents conflicts between simultaneous readers and writers, compared to simpler IPC mechanisms like files and FIFOs.