The Linux kernel creates a file for a Unix domain socket bound to a pathname.
Does the Linux kernel create a file for an Internet domain socket?
No, not in the sense of a file on hard-drive or other block device.
If you look at socket.c in Linux source code, you will see that it creates an inode for sockets, however data is in sockfs filesystem, which is a virtual filesystem within kernel itself, and space is allocated via kmalloc type of function. In that sense, sockets are anonymous files residing in memory.
This brings back to the concept of "everything is a file in Unix", which is a design pattern that focuses on having common utilities to perform same functions similar to files on real physical media. As Linus Torvalds stated:
The whole point with "everything is a file" is not that you have some random filename (indeed, sockets and pipes show that "file" and "filename" have nothing to do with each other), but the fact that you can use common tools to operate on different things.
Thus sockets have inode to have file-like access, but not present on physical filesystem.
However, note, there exist Unix domain sockets, which are IPC type of object intended for process networking, and do reside on disk filesystems.
lsof
output: "0xffff8803e256d9c0. That number is actually the address of the relevant in-kernel memory structure or type struct unix_sock". So there has to be an inode in kernel's virtual filesystem corresponding to that
Commented
Jan 6, 2019 at 2:44
The Linux kernel creates a file for a Unix domain socket bound to a pathname.
OK.
Does the Linux kernel create a file for an Internet domain socket?
No. Binding a socket to an IP address+port does not synthesize a pathname. It does not create a file somewhere you can see.
bind()
on a AF_INET
/ AF_INET6
socket does not create any file on any physical filesystem. The bind()
call will not generate a file on any of the builtin virtual filesystems. (Of course you can write your own FUSE filesystem, which mimics netstat -46
in some way, so that it creates a new file).