Skip to content
Advertisement

(deleted) file creating issue on Linux

My process reads a files and deletes it. This activity happens more than 2000 times.

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). But I see 1024 records, with 1020 being the (deleted) entries. Later the new file operation from this PID fails.

To overcome this issue, kept process on debug and did

p close (id)

This (id) is taken from ll output on /proc/PID/fd.

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)

Advertisement

Answer

/proc/$PID/fd directory shows all the open files of the process named by their descriptors. 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.

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). 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

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement