简体   繁体   English

Linux上(已删除)文件创建问题

[英](deleted) file creating issue on Linux

My process reads a files and deletes it. 我的进程读取文件并将其删除。 This activity happens more than 2000 times. 这项活动发生了2000次以上。

When I check the file in /proc/PID/fd, I see the file there and I see at the end of each line as (deleted) . 当我检查/ proc / PID / fd中的文件时,我看到该文件,并且在每一行的末尾都看到(deleted) But I see 1024 records, with 1020 being the (deleted) entries. 但是我看到1024条记录,其中1020条是(已删除)条目。 Later the new file operation from this PID fails. 后来,此PID进行的新文件操作失败。

To overcome this issue, kept process on debug and did 为了解决此问题,请在调试时保持流程,并执行

p close (id) p关闭(id)

This (id) is taken from ll output on /proc/PID/fd. 此(id)取自/ proc / PID / fd上的ll输出。

Wanted to know the reason for the file not being deleted. 想知道文件未删除的原因。 fdclose is used first and then the file is deleted, even then file is shown with (deleted) 首先使用fdclose ,然后删除文件,即使文件显示为(已删除)

/proc/$PID/fd directory shows all the open files of the process named by their descriptors. / proc / $ PID / fd目录显示由其描述符命名的进程的所有打开文件。 Each file in /proc/$PID/fd represents an open file/socket/pipe etc., If the descriptor belongs to a disk file, then its symbolic link points to the absolute path of the file that is opened. / proc / $ PID / fd中的每个文件都表示一个打开的文件/套接字/管道等。如果描述符属于磁盘文件,则其符号链接指向打开的文件的绝对路径。

Here, (deleted) represents that the file that is opened by the process is deleted and no longer exist on disk. 此处, (已删除)表示该进程打开的文件已删除,并且在磁盘上不再存在。 So, the issue in your case is that the file that is opened is not getting closed before unlink(delete). 因此,您遇到的问题是,打开的文件在unlink(delete)之前没有被关闭。 You need to close them before deleting it otherwise it leaks file descriptors. 您需要先删除它们,然后再删除文件描述符。

If you are coding in C use fclose(C standard) or close(POSIX) appropriately to close the file before 如果您使用C进行编码,请先使用fclose(C standard)或close(POSIX)适当地关闭文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM