Say I have the following Node program, a machine that goes \"Ping!\":
var machine = require(\'fs\').createWriteStream(\'machine.log\', {
flags : \'a\'
The writes actually do not fail.
When you delete a file that is open in another program you are deleting a named link to that file's inode. The program that has it open still points to that inode. It will happily keep writing to it, actually writing to disk. Only now you don't have a way to look it at, because you deleted the named reference to it. (If there were other references, e.g. hard links, you would still be able to!).
That's why programs that expect their log files to "disappear" (b/c of logrotate
, say) usually support a signal (usually SIGHUP
and sometimes SIGUSR1
) that tells them to close their file (at which point it is really gone, because now there are no links to it anywhere) and re-create it.
You should consider something like that as well.