LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   In a cpp application I am deleting a file on a partition, but space is not freeing.. (https://www.linuxquestions.org/questions/linux-newbie-8/in-a-cpp-application-i-am-deleting-a-file-on-a-partition-but-space-is-not-freeing-4175544480/)

adlingepa 06-04-2015 08:38 AM

In a cpp application I am deleting a file on a partition, but space is not freeing..
 
1) deleting file using remove() call
2) no other hard link for the file
3) tried to close file descriptor using following scripts then remove() call
-------
for fd in $(ls /proc/$$/fd); do
case "$fd" in
0|1|2|255)
;;
*)
eval "exec $fd>&-"
;;
esac
done
-------

But space not freed

4) I tried with truncate() and then remove() call Now files deleted and space freed

Is it the only and right way to do this?

smallpond 06-04-2015 08:54 AM

From the man page for remove:

Quote:

If the removed name was the last link to a file and no processes have the file open, the file is deleted and the space it was using is made available for reuse.

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.

pan64 06-04-2015 09:39 AM

I think your for cycle does not work, it is simple not possible (to close a file descriptor from outside, from another process - for example from a shell script).

joec@home 06-05-2015 04:37 PM

Quote:

Originally Posted by pan64 (Post 5372065)
I think your for cycle does not work, it is simple not possible (to close a file descriptor from outside, from another process - for example from a shell script).

There is in theory another way to do this, though I would have to dig though my notes on how to remove the flag of open files by PID. However if anything did go wrong your looking at a corrupt file table on your format. I think it might be better to trace the PID of the offending process and kill it. Barking up any other tree might just trash your entire disk.


All times are GMT -5. The time now is 07:09 PM.