Issue
I know if a unix process forks, the child process can use fd from father. This is inheritance: but not vice versa.
While the unix advance programing materials say if we use unix domain socket, not only we can transfer a fd from child to father, but also between processes.
This is weird:
an fd is only meaningful within one process, in different process, same fd value could mean very different.
Then how could unix domain socket really transfer fds between processes? I mean the integer (4 bytes) can be transferred by any means, but it doesn't seem to make sence that one process can operate another process's fd?
Any explanations?
Solution
You should really try that yourself. As it said in the man page of unix(7):
SCM_RIGHTS
Send or receive a set of open file descriptors from another
process. The data portion contains an integer array of the
file descriptors. The passed file descriptors behave as
though they have been created with dup(2).
that means the fds received are not equal to the ones sent as in numbers, they're like newly created fds, but they're actually the same thing in the kernel's perspective of view.
Answered By - Hualet