LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-04-2015, 09:38 AM   #1
adlingepa
LQ Newbie
 
Registered: Jun 2015
Posts: 1

Rep: Reputation: Disabled
Post 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?

Last edited by adlingepa; 06-04-2015 at 09:40 AM.
 
Old 06-04-2015, 09:54 AM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 (pre-systemd)
Posts: 2,667

Rep: Reputation: 710Reputation: 710Reputation: 710Reputation: 710Reputation: 710Reputation: 710Reputation: 710
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.
 
Old 06-04-2015, 10:39 AM   #3
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 8,516

Rep: Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436Reputation: 2436
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).
 
Old 06-05-2015, 05:37 PM   #4
joec@home
Member
 
Registered: Sep 2009
Location: Galveston Tx
Posts: 291

Rep: Reputation: 70
Quote:
Originally Posted by pan64 View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Not Freeing up disk space after deleting files centos 5.6 bit 64 Rohant Linux - Server 5 04-01-2014 01:56 PM
Redhat 5 not freeing space after deleting files. akharejhansi Linux - Hardware 5 10-25-2010 04:14 AM
Freeing up disk space after removing a file with 'rm' jaysun834 Linux - General 11 11-18-2009 08:45 AM
Freeing space; deleting subdirs after installs intermod Linux - General 2 01-01-2008 04:58 PM
out of space on partition, need help freeing up room disorderly Linux - Newbie 2 10-18-2004 02:44 PM


All times are GMT -5. The time now is 04:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration