Chapter 17: Advanced Inter-Process Communication

Chapter 17: Advanced Inter-Process Communication

Chapter 17: Advanced Inter-Process Communication

UNIX Domain Sockets

UNIX domain sockets are specifically designed for communication between processes on the same computer. Compared to internet sockets, they offer higher efficiency as they only transmit data without executing protocol processing.

A created UNIX domain socket can function as a full-duplex pipe, with both ends open for reading and writing, known as an fd pipe.

Application Scenarios:

  • Solving the problem that message queues cannot use select or poll

  • socketpair creates a pair of sockets, unnamed

  • Binding to an address like xxx.socket, named

Using UNIX domain sockets enables transmission of open files between two processes by passing file descriptors through send_fd. Two processes can share the file offset, where the client doesn’t directly obtain the file content but rather the shared file descriptor, significantly reducing data copying.