Unix domain socket
{{short description|Communications endpoint for exchanging data between processes executing in the same operating system}}
A Unix domain socket (UDS), a.k.a. local socket, a.k.a. inter-process communication (IPC) 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:{{cite web
| url = http://man7.org/linux/man-pages/man7/unix.7.html
| date = 30 April 2018
| title = Linux Programmer's Manual (unix - sockets for local interprocess communication)
| access-date = 22 February 2019
| df = dmy-all}}
SOCK_STREAM
(compare to TCP) – for a stream-oriented socketSOCK_DGRAM
(compare to UDP) – for a datagram-oriented socket that preserves message boundaries (as on most UNIX implementations, UNIX domain datagram sockets are always reliable and don't reorder datagrams)SOCK_SEQPACKET
(compare to SCTP) – 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 name space. 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.{{cite web |url=http://archives.neohapsis.com/archives/postfix/2000-09/1476.html |date=30 September 2000 |title=Archive of the "Postfix Discussions" mailing list |access-date=29 September 2014 |archive-url=https://web.archive.org/web/20130518084034/http://archives.neohapsis.com/archives/postfix/2000-09/1476.html |archive-date=18 May 2013 |url-status=dead |df=dmy-all}}{{cite web |url=https://linux.die.net/man/3/cmsg |title=Linux man page - cmsg(3): access ancillary data |access-date=9 October 2018 |df=dmy-all}} This can be used to implement a rudimentary form of capability-based security.{{cite web |url=https://www.dwheeler.com/secure-programs/Secure-Programs-HOWTO/sockets.html |title="Secure Programming for Linux and Unix HOWTO", Section 3.4 "Sockets and Network Connections" |date=22 August 2004 |website=dwheeler.com |publisher=David A. Wheeler |access-date=29 September 2014}}
See also
- {{Annotated link|Network socket}}
- {{Annotated link|Berkeley sockets}}
- {{Annotated link|Pipeline (Unix)}}
- {{Annotated link|Netlink}}
References
{{Reflist}}
External links
- {{man|sh|socket|SUS||create a socket}}
- {{man|sh|socketpair|SUS||create a pair of connected sockets}}
- {{man|sh|sendmsg|SUS||send a message on a socket}}
- {{man|sh|recvmsg|SUS||receive a message from a socket}}
- {{man|3|cmsg|Linux||socket ancillary data, including sending/receiving file descriptors}}
- [https://untroubled.org/ucspi-unix/ ucspi-unix], UNIX-domain socket client-server command-line tools
- [https://lists.freebsd.org/pipermail/freebsd-performance/2005-February/001143.html Unix sockets vs Internet sockets]
- [https://beej.us/guide/bgipc/html/multi/index.html Unix Sockets - Beej's Guide to Unix IPC]
{{Inter-process communication}}
{{Use dmy dates|date=January 2019}}