2

I was using lsof to track down deleted files that were still taking up space and I realized that I wasn't quite sure what an offset is with respect to a file. lsof's man page was less than helpful in this regard and searching around I couldn't get a clear picture of what it is.

What is a file offset and why is it useful to have that piece of information?

4

The offset is the current position in the file, as maintained by the kernel for a given file descriptor (see the lseek(2) manpage for details).

As to why it's useful in lsof's output, I'm not really sure. It can give some idea of a process's progress through a file, although it won't cover all cases (memory-mapped files won't show offset changes).

1

Stephen Kitt's answer is close, but not quite correct; if we read lseek(2) more carefully, we will see that it actually says (bold mine):

The lseek() function repositions the file offset of the open file description associated with the file descriptor fd [...]

So, what's an "open file description" and how does it relate to a "file descriptor"?

Well, down in the NOTES section, we find:

See open(2) for a discussion of the relationship between file descriptors, open file descriptions, and files.

Perfect! However, rather than pasting a wall of text from the manpage, I'll just link to a good answer to "What is an open file description?" that explains the same thing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.