7

When using socket in the UNIX domain, it is advisable to use path name for the directory directory mounted on the local disk. The UNIX domain only allows interprocess communication for process working on same machine.

Can you please explain the above line? It is about a socket in the UNIX DOMAIN.

Thanks!

3 Answers 3

12

A Unix domain socket or IPC socket (inter-process communication socket) is a data communications endpoint that is similar to an Internet socket, but does not use a network protocol for communication. It is used in POSIX operating systems for inter-process communication. The correct standard POSIX term is POSIX Local IPC Sockets.

Unix domain connections appear as byte streams, much like network connections, but all data remains within the local computer. UNIX domain sockets use the file system as address name space, i.e. they are referenced by processes as inodes in the file system. This allows two distinct processes to open the same socket in order to communicate. However, the actual communication (the data exchange) does not use the file system, but buffers in kernel memory.

In addition to sending data, processes can send file descriptors across a Unix domain socket connection using the sendmsg() and recvmsg() system calls.

6
  • thanks for reply, so unix domain socket is for interprocess communication between two process on the same system,just like any other ipc mechanism like sharedmemory.So using unix domain we cant make communication between two machine.
    – mawia
    Apr 23, 2009 at 19:22
  • 1
    @mawia - that is correct. For instance, you can talk to the local X window server over a Unix Domain Socket by setting your DISPLAY environment variable to ":0.0" or over a TCP/IP socket by setting it to "localhost:0.0". Apr 23, 2009 at 19:26
  • Look up AF_INET for the IP sockets to communicate between different hosts.
    – user39113
    Apr 23, 2009 at 19:27
  • 2
    Just one thing that doesn't sound right: "Unix domain connections appear as byte streams": Local sockets can be both byte streams (SOCK_STREAM) and datagrams (SOCK_DGRAM and SOCK_SEQPACKET).
    – Juliano
    Apr 23, 2009 at 19:36
  • 1
    AF_UNIX already makes it sound quite UNIX-specific, no? On the other hand, the synonyms AF_FILE and AF_LOCAL might have enlightened OP more than the common AF_UNIX name...
    – ephemient
    Apr 23, 2009 at 22:14
4

The end-points of UNIX domain sockets are represented by files in the file system (instead of by host / port).

However the communication between processes is done within the local system and does not result in a seekable file getting stored anywhere.

The advantage of using the file system as the namespace for the end-points is that normal file permissions and ACLs can be applied - if you can't open the end-point you can't connect. IP sockets have no such mechanism.

2
  • /*ACLs can be applied - if you can't open the end-point you can't connect.*/ plz explain the above lines of your's.
    – mawia
    Apr 25, 2009 at 17:32
  • 1
    it means that (for example) if the UNIX filename is chmod 0700 only the owner of the file (or root) can open the socket. Thus there is an extra level of security applied before the socket may even be opened.
    – Alnitak
    Apr 25, 2009 at 17:49
4

It means that if you create a AF_UNIX socket on a NFS disk which is shared between two machines A and B, you cannot have a process on A writing data to the unix socket and a process on B reading data from that socket.

The communication happens at kernel level, and you can only transfer data among processes sitting in the same kernel.

1
  • I wish NFS had the option to proxy those. I find mount permissions (default deny) more convenient than netfilter (default allow).
    – Tobu
    Jan 10, 2011 at 22:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.