Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Imagine a bunch of processes using a /home/user/logs directory. They have some logs open for a longer time.

share|improve this question

2 Answers 2

Processes usually do not keep files open in logs for long.

Yes, you can move / delete any directory or file which is in use by any process at any time. Heck, you can delete the process' executable while it is running and it will continue to run.

However, prepare for some possible scenarios:

  • when processes will reopen for writing log files they will recreate them.
  • processes will continue to write to the old location not the new one
  • if you delete the executable of a process, you will not be able to start it again

Files will be physically cleared on delete when no process will use their descriptors. You will see the files moved / deleted immediately.

share|improve this answer

Yes, under certain conditions. The inodes of the files won't change if you move their parent directory, so the open file handles will still be valid. The conditions are:

  • You don't move the directory across filesystems. That'd change the inode numbers of the files, of course.
  • The processes actually do keep the files open, and don't close them on occasion (if so, you'll have to reconfigure the applications to make them aware of the new parent directory)
  • You're using ext2/3/4 or one of the various versions of ufs out there. I can't honestly speak about other fileystems because I'm not sure how they're organised internally.
share|improve this answer
2  
This is true for any filesystem and for any unix variant (except for executables on some unix variants). The open file is tied to an inode, not to the name of the file, and it doesn't matter if the file is renamed or even deleted. –  Gilles Jan 16 '12 at 19:50
    
That's true in-core, but out-of-core, the filesystem's structures and operations reign supreme. And Linux can talk to a whole sleuth of weird filesystems. I just don't like making generalisations — I've seen too many weird things for that. There could, conceivably, exist an exotic filesystem which (for reasons unknown) creates new inodes when a file is moved across directories. Perhaps because the inode paradigm doesn't map cleanly to that filesystem. There are always degrees of freedom, so I have to talk about what I'm sure about. –  Alexios Jan 23 '12 at 21:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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