Removal of the nohup -file during the execution
-
18-09-2019 - |
Question
I did the following:
nohup find / &
rm nohup.out
Oddly, the nohup -command continued to run. I awaited for a new file to be created. For my surprise there was no such file. Where did the stdout of the command go?
Solution
Removing a file in UNIX does two things:
- it removes the directory entry for it.
- if no processes have it open and no other directory entries point to it (hard links), it releases the space.
Your nohupped process will gladly continue to write to the file that used to be called nohup.out, but is now known as nothing but a file descriptor within that process.
You can even have another process create a nohup.out, it won't interfere with the first.
When all hard links are gone, and all processes have closed it, the disk space will be recovered.
OTHER TIPS
if you will delete the nohup.out
file, the handle will be lost and it will write only to the file descriptor but if you want to clean out the nohup.out
file then just run this
true > nohup.out
it will delete the contents of the file but not the file.
That's standard behaviour on Unix.
When you removed the file, the last link in the file system was removed, but the file was still open and therefore the output of find
(in this case) was written to disk blocks in the kernel buffer pool, and possibly even to disk. But the file had no name. When find
exited, no process or file (inode) referenced the file, so the space was released. This is one way that temporary files that will vanish when a program exits are created - by opening the file and then removing it. (This presumes you do not need a name for the file; clearly, if you need a name for the temporary, this technique won't work.)
cat /dev/null > nohup.out
from here