4
SERVER:~ # df -mP /home/
Filesystem         1048576-blocks      Used Available Capacity Mounted on
/dev/mapper/rootvg-home_lv       496       491         0     100% /home
SERVER:~ # 
SERVER:/home # lsof | grep -i deleted | grep -i "home" | grep home
badprocess   4315     root  135u   REG      253,2   133525523      61982 /home/username/tr5J6fRJ (deleted)
badprocess2  44654     root  133u   REG      253,2   144352676      61983 /home/username/rr2sxv4L (deleted)
...
SERVER:/home # 

Files were deleted while they were still in use. So they still consume space. But we don't want to restart the "badprocess*". OS is SLES9, but we are asking this "in general".

Question: How can we remove these already deleted files without restarting the process that holds them, so the space would free up?

6

You can use the entries in /proc to truncate such files.

# ls -l /proc/4315/fd

That will show all the files opened by process 4315. You've already used lsof and that shows that the deleted file is file descriptor 135, so you can free the space used by that deleted file as follows:

# > /proc/4315/fd/135

The same goes for the other deleted file opened by process 44654, there it's file descriptor 133, so:

# > /proc/44654/fd/133

You should now see that the space is freed up.

You can also use this to copy the contents of a file that's been deleted but still held open by a process, just cp /proc/XXX/fd/YY /some/other/place/filename.

  • Can one also create a hard link to that fd in the original directory with ln instead of cp? – Nils Jan 24 '15 at 22:30
  • No, because all you have is a symlink. You won't be able to create a link to the symlink as that would be over different filesystems, and the target of the symlink doesn't exist anymore; that you can access the contents of the deleted file this way is a special case, other operations (related to the inode and not the contents) won't work. – wurtel Jan 26 '15 at 11:39
0

Short of connecting to badprocess using a debugger or something else that uses the ptrace() facility to manipulate the process and cause it to close some of its files, I don't think there's any way to do that.

Your title talks about locks but you don't mention locks in the body of your question. Anyway, there is also no way to forcibly make a process give up a lock it has on a file. That's true whether the file is still linked in the filesystem or not.

Your Answer

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