Linux “lsof”将文件显示为(已删除)但我仍然可以在文件系统中看到它
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18200701/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"lsof" shows a file as (deleted) but I can still see it in file system
提问by user1783732
in Linux 2.6.27:
在 Linux 2.6.27 中:
From "lsof" output I see a process holding open fd with a (deleted) file. The strange thing is that I can still see the file in the file system using "ls". Why is that?
从“lsof”输出中,我看到一个进程使用(已删除)文件保持打开的 fd。奇怪的是,我仍然可以使用“ls”看到文件系统中的文件。这是为什么?
thanks.
谢谢。
回答by mohit
The file is not deleted as long as some process has the file open. When a file is closed, the kernel first checks the count of the number of process that have the file open. If this count has reached 0, the kernel then checks the link count; if it is 0, the file's contents are deleted.
只要某个进程打开了该文件,该文件就不会被删除。当文件关闭时,内核首先检查打开文件的进程数。如果此计数已达到 0,则内核会检查链接计数;如果为 0,则删除文件内容。
To quote from man unlink:
引用 man unlink:
If the name was the last link to a file but any processes still have the file open the file will remain in existence until the last file descriptor referring to it is closed.
如果名称是文件的最后一个链接,但任何进程仍然打开该文件,则该文件将一直存在,直到最后一个引用它的文件描述符关闭。
回答by fefe
When a file is deleted it would not been seen on the file system. However, it is quite possible another file with the same file name is created on the same location.
当一个文件被删除时,它不会出现在文件系统上。但是,很可能在同一位置创建了另一个具有相同文件名的文件。
You can check the node number shown in lsof
and ls -i
to check whether they are really the same file.
您可以检查lsof
和 中显示的节点号ls -i
来检查它们是否真的是同一个文件。