Thursday, May 27, 2010

Link Count Of Zero

Met up with some clever guys yesterday and they made me think how Solaris treat deleted files which are still open. We know that if we hard link files in the same file system, it will increment the link count. Do you know that if you delete an open file (with link count of 1), the link count will be become zero (decrement by one). Since the file handler is still open, the kernel will not release those space occupied by the file. So, if you were to do a ls -al, you will see the link count of zero.

To efficiently finding how much space has been taken up by these deleted open files, the below one-liner is able to extract that from find and summaries it by AWK. Here is the output from one of my systems.

# find /proc/*/fd -type f -links 0 -ls | awk '{s+=$7}END{print s}'

This link explained very clearly how the situation come about.



Blogger Macross said...

Or use losf

Help me trace an "orphaned" log eating up diskspace at 1MB/s.
Application Engineer claimed he had turned off the logger properly.
Had to restart the Application.

Pardon for my poor grammar (never good) :)

10:27 PM  
Blogger chihungchan said...

Thanks. However, lsof does not come with Solaris by default.

10:14 PM  

Post a Comment

<< Home