我正在尝试制作一个支持打开、关闭、读取和写入操作的 linux 内核模块。 所以我想通过 struct file_operations 注册这些函数,但是我在结构中找不到“关闭”条目。 我想我应该使用'release'而不是'close',但我想知道为什么名称是'release'而不是'close'?
最佳答案
因为文件可能被打开多次,当你关闭一个描述符时,只有在最后一次关闭调用文件的最后一次引用时才会调用 release。所以close和release是有区别的。
release: called at the last close(2) of this file, i.e. when file->f_count reaches 0. Although defined as returning int, the return value is ignored by VFS (see fs/file_table.c:__fput()). more
关于linux - 为什么在Linux内核中close函数在 `struct file_operations`调用release?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11393674/