Advanced · Module 6 · Lesson 8 of 10
Unix Domain Sockets and File Descriptor Passing
Establish bidirectional inter-process streams with AF_UNIX, pass live open file descriptors across process boundaries using sendmsg and SCM_RIGHTS, and authenticate peer credentials.
By the end you can
- Construct bidirectional stream and datagram channels using AF_UNIX and socketpair
- Transmit open kernel file descriptors across process boundaries via sendmsg and SCM_RIGHTS
- Parse ancillary control messages using CMSG_FIRSTHDR, CMSG_DATA, and CMSG_SPACE macros
- Verify peer process identity (PID, UID, GID) using SO_PEERCRED
01 · A question first
Why can an unprivileged worker process with no filesystem permissions read a protected file after receiving an 8-byte message from a privileged daemon? And why is sending an integer fd over a pipe useless, while passing it over a Unix domain socket gives the recipient a live kernel handle?
Make a guess before you read on.
02 · The idea
Members only
Unlock the full lesson
This lesson is part of the membership. Join to read it in full, along with every other premium deep dive.
What's inside
- Start with the problem
- How the idea works
- Production Implementation: Passing Descriptors
- Why it is correct
- What it costs
- Pitfalls and variations
- Where it is used
- Core Track: Modules 1–3 Complete
03 · Practice
Asked in interviews
Something wrong with this lesson? Report a problem