1825775 Members
2103 Online
109687 Solutions
New Discussion

Re: busy file

 
Prashanth Waugh
Esteemed Contributor

busy file


hi,
I AM trying to copy the file to another destination it is showing busy.so can i
use #fuser -ku
Thanks
For success, attitude is equally as important as ability
4 REPLIES 4
Dennis Handly
Acclaimed Contributor

Re: busy file

I assume the target of the copy is busy and it is an executable or shlib?

There is no need to use a fuser/lsof hammer. Just use ln -f and teach that guy a lesson: ;-)
cp path/file file.new
ln file file.old
ln -f file.new file
rm file.new
Wim Rombauts
Honored Contributor

Re: busy file

I guess that even a

"mv targetfile targetfile.old"

followed by a

"cp sourcefile targetfile"

should work. The targetfile is opened by it's inode, and by moving the file, the inode remains untouched, just the name is changed. The current user will keep using the old file until he closes and reopens it. New users wil use the new file.
whiteknight
Honored Contributor

Re: busy file


Hi,

A busy file on UNIX is one which cannot be unlinked (unlink(2)), not necessarily any open file as reported by fuser(1M). Busy and open being synonymous is the case with Windows.

When a file is overwritten, its inode (the pointer to the data, named by the file's name) is unlinked from the data. If a process has the data open, then that data will continue to use disk space until the process exits. But since the inode could be unlinked from the old data, the file name is free to be used for a new inode pointing to the restored data.

Had the unlink(2) failed, common with shared library files, then the inode would be renamed to # from . Then the old filename would be free to use with a new inode pointing to the restored data, while the old inode, now named #, still points to the old data.

WK
Problem never ends, you must know how to fix it
Dennis Handly
Acclaimed Contributor

Re: busy file

>Wim: I guess that even a "mv" followed by a "cp" should work.

This won't work in all cases. I.e. replacing dld.
Only ln(1) works, so don't settle for cheap imitations. ;-)

>WK: Had the unlink(2) failed, common with shared library files, then the inode would be renamed to # from .

This "#" convention is a manual process, which must be programmed into the script.