Unix-domain socket
A Unix-domain socket is an operating-system communication endpoint for exchanging data between processes on the same host.
Address: AF_UNIX (AF_LOCAL) supports pathname and unnamed sockets; Linux adds abstract names outside the filesystem. After the leading null byte, address length selects the name bytes; further nulls are not terminators. [1]
Unnamed channel: socketpair(AF_UNIX, SOCK_STREAM, 0, sv) returns two connected, unnamed endpoints. It creates no pathname to preserve in a directory backup. [6]
File type: S_ISSOCK(st_mode) identifies a socket node, not a regular file or message archive. [2] bind() assigns an address. [3] Closing a pathname socket does not unlink its name. [1]
Framing: SOCK_STREAM has no record boundaries. A SOCK_SEQPACKET receive call with insufficient application-buffer space can discard the packet remainder. [4] Linux AF_UNIX SOCK_DGRAM preserves reliable, ordered messages; SOCK_SEQPACKET is connection-oriented and preserves message boundaries and order. [1]
Access and lifetime: Linux pathname creation requires parent-directory write and search permission. Socket write permission gates stream connection and datagram sending; this check is not portable. Abstract names use neither pathname permissions nor umask and disappear after all open references close. [1]
Descriptor handoff: SCM_RIGHTS transfers references to open file descriptions, not file-content copies. [1]
Persistence: Successful send() is not an acknowledgment of peer processing or durable storage. Requiring an application completion and recovery contract is an engineering inference, not a crash experiment. [5]
Historical scope: Berkeley's July 1983 4.2BSD primer separates domain from type and describes generic datagrams without guaranteed reliability; today's Linux AF_UNIX guarantee is domain-specific. [7] [1]
Relations
- related
- Inode, Open file description
Limitations
- Linux abstract addresses are not a portable filesystem namespace.
- Reliable local communication is not a durable-storage guarantee.
Citations
- Linux man-pages: unix(7), local addresses, permissions and descriptor passing
- Linux man-pages: inode(7), socket and regular-file types
- Linux man-pages: bind(2), address assignment and pathname cleanup
- Linux man-pages: socket(2), endpoint and socket-type contracts
- Linux man-pages: send(2), local completion and error reporting
- Linux man-pages: socketpair(2), connected unnamed endpoints
- Leffler, Fabry and Joy: A 4.2bsd Interprocess Communication Primer, UCB/CSD-83-145 (July 27, 1983), sections 2 and 2.1
Further reading
Sources & caveats
- Primary-source documentation synthesis; no new socket, permission or crash experiment.
- Linux-specific address and access rules are distinguished from portable application guarantees.