Linux Kernel - Socket file descriptor close location
Where in开发者_StackOverflow中文版 the linux kernel does the closing of a socket's file descriptor occur? I know for a file, the file's file descriptor is closed in fs/open.cs function sys_close(). However, for a socket file descriptor, is this the same location or somewhere else?
Also, do sockets utilize the file.c alloc_fd to allocate the file descriptor or do they utilize some other function?
Yes, sys_close()
is the entry point for closing all file descriptors, including sockets.
sys_close()
calls filp_close()
, which calls fput()
on the struct file
object. When the last reference to the struct file
has been put, fput()
calls the file object's .release()
method, which for sockets, is the sock_close()
function in net/socket.c
.
The socket code uses get_unused_fd()
and put_unused_fd()
to acquire and release file descriptors.
精彩评论