A process is creating huge number of log files and also deleting it.

Many of those deleted files are having broken links in the /proc/pid/fd directory.

Do these file handles need to be closed by process? So that i shouldn't see the broken links. I am calculating the number of file descriptors by using below command:

ls /proc/<pid>/fd | wc -l
  • What does ls -l /proc/$pid/fd show? There shouldn't be broken links. – ams Mar 16 '16 at 15:04

If a process has a file open and that file is deleted, the file appears as a broken link in /proc/PID/fd. That's perfectly normal. A broken link is not in itself an indication that something is wrong.

If a program is keeping a lot of files open but not doing anything with them, that might indicate a bug in the program. Keeping a deleted file open has some uses, but for a log file, it doesn't make any sense, so if those are indeed log files, there's probably a bug in the program. You'll have to contact the program's author to get it fixed (or do it yourself if you have the source).

There's no way to act on the process via /proc. You can attach a debugger to the process and make it close the files, but the results are not guaranteed. It's like removing the ladder under someone who's climbing onto a roof: they're likely to fall and get badly hurt. If you want to reclaim the disk space, you can truncate the files via /proc: the shell command : >/proc/PID/fd/NUMBER will do the trick. If the program keeps writing to the file, this will again start using disk space; a way to avoid that would be to use a debugger to cause the process to dup2 a file descriptor that's open to /dev/null, but we're back to results that are not guaranteed.

  • Thanks a lot . I will ask program owner to handle open file handles/descriptors. – Gaurav KS Mar 19 '16 at 19:33
  • @GauravKS Good! If this solves your issue, please consider "accepting" the answer. This is the best way to show gratitude on this site. Accepting an answer not only marks the question as resolved, but also signals to future readers that the accepted answer actually solved the issue. More information about this is available here: unix.stackexchange.com/help/someone-answers – Kusalananda Apr 8 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.