Hardlink to a node?

Hardlink to a node?

am 29.01.2008 07:27:03 von jellybean stonerfish

One day while using streamripper to grab some streaming music, I
decided to experiment with my system. So I deleted the file streamripper
was writing to. Using "ls" it looks like the file is gone, but using "df"
it looks like the disk is still being written to. I think that when I
delete a file, a program using that file still has a pointer to it and can
write to the file, even when "ls" shows no file there. Is this close to
correct?

lsof | grep streamrip shows the file and a number for the node.

Is there a command to make a hard link to a file if you know the node
number?

Re: Hardlink to a node?

am 29.01.2008 10:05:54 von PK

jellybean stonerfish wrote:

> One day while using streamripper to grab some streaming music, I
> decided to experiment with my system. So I deleted the file streamripper
> was writing to. Using "ls" it looks like the file is gone, but using "df"
> it looks like the disk is still being written to. I think that when I
> delete a file, a program using that file still has a pointer to it and can
> write to the file, even when "ls" shows no file there. Is this close to
> correct?

Yes, in unix-like systems the file is not deleted from disk as long as there
are open descriptors pointing to it. Another way you can see that is (for
example) running scp user@hostA:file1 from hostB. Then, while the file is
still copying, log in to hostA and delete file1. The scp on hostB will go
on and complete.
Another use of the feature is for creating temporary files. A program
creates and opens a temporary file, say /tmp/tmpfile, and then immediately
does an unlink() on it. Other processes won't see the file since it has
been unlinked, but the program which created it can still use it as long as
it keeps it open and has a descriptor to it. When the program terminates,
the OS transparently removes the file from disk.

> lsof | grep streamrip shows the file and a number for the node.
>
> Is there a command to make a hard link to a file if you know the node
> number?

None that I know of (but of course I might be wrong).