Contents
What is file descriptor in socket?
A socket is an abstraction of a communication endpoint. Socket descriptors are implemented as file descriptors in the UNIX System. Indeed, many of the functions that deal with file descriptors, such as read and write, will work with a socket descriptor.
What are the differences between sockets and file descriptors why would you use one or the other?
The main difference between sockets and files is that the operating system binds file descriptors to a file or device when the open() call creates the file descriptor. Because each file or socket has a unique descriptor, the system knows exactly where to send and to receive the data.
Where does socket go in the file descriptor table?
Socket is nothing but a file in UNIX operating system. Even everything is treated as a file in UNIX Operating system. Whenever we create a socket an entry is made in the file descriptor table which contains standard i/o and standard errors and other details.
Where are the file descriptors open in a process located?
The process does not have direct access to the file or inode tables. On Linux, the set of file descriptors open in a process can be accessed under the path /proc/PID/fd/, where PID is the process identifier. In Unix-like systems, file descriptors can refer to any Unix file type named in a file system.
How is socket treated as a file in Unix?
Each process has its own “file” descriptor table. Socket is nothing but a file in UNIX operating system. Even everything is treated as a file in UNIX Operating system. Whenever we create a socket an entry is made in the file descriptor table which contains standard i/o and standard errors and other details.
How to exchange file descriptors using domain sockets?
To exchange file descriptors using UNIX domain sockets, we call the sendmsg (2) and recvmsg (2) functions ( Section 16.5 ). Both functions take a pointer to a msghdr structure that contains all the information on what to send or receive. The structure on your system might look similar to the following: