Unix domain socket


A Unix domain socket, local socket, or inter-process communication 'socket' is a communication endpoint for exchanging data between processes executing in the same Unix or Unix-like operating system.
The name Unix domain socket refers to the domain argument value AF_UNIX that is passed to the function that creates a socket system resource. The same communication domain is also selected by AF_LOCAL.
Valid type argument values for a UDS are:
  • SOCK_STREAM – for a stream-oriented socket
  • SOCK_DGRAM – for a datagram-oriented socket that preserves message boundaries
  • SOCK_SEQPACKET – for a sequenced-packet socket that is connection-oriented, preserves message boundaries, and delivers messages in the order that they were sent
The UDS facility is a standard component of a POSIX operating system.
The API for a UDS is similar to that of an Internet socket, but rather than using an underlying network protocol, all communication occurs entirely within the operating system kernel. A UDS may use the file system as its address namespace. Some operating systems, like Linux, offer additional namespaces. Processes reference a UDS as a file system inode, so two processes can communicate by opening the same socket.
In addition to sending data, processes may send file descriptors across a UDS connection using the sendmsg and recvmsg system calls. This allows the sending processes to grant the receiving process access to a file descriptor for which the receiving process otherwise does not have access. This can be used to implement a rudimentary form of capability-based security.