Removal of the nohup -file during the execution

Léo Léopold Hertz 준영 picture Léo Léopold Hertz 준영 · Apr 28, 2009 · Viewed 17.2k times · Source

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?

Answer

paxdiablo picture paxdiablo · Apr 28, 2009

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.