3

I'm starting to read Linux Systems Programming, 2nd Ed., and I was curious about the file table that is a "per-process list of open files." Is the file table like a table in a SQL db with the fds used as primary keys? If so, does this mean that the entries are repeated, or is it split into separate tables and normalized?

Or does it work entirely differently since we're dealing with straight C/assembly? If so, what data structures are used?

Where in the source is this subsystem defined? Most of the reason I'm doing this is to understand both C and Linux better. If I know where to find it, that would give me a better idea.

  • 2
    That would be Linux kernel code. No, there won't be any SQL stuff. – jordanm Jan 9 '15 at 18:47
  • I would bet it is implemented as a double-linked-list in the kernel code. Haven't checked though. See lsof source code for access details. – user86969 Jan 9 '15 at 18:48
6

Since this is C, "table" is likely short for "array of structures".

You probably want to read "Understanding the Linux Kernel" or "Linux Kernel Development".

Or do it the hard way and read the source; good places to start might be:
include/linux/fdtable.h and
include/linux/fs.h.

  • This gives me a good place to start. the fdtable.h does have a struct for "fdtable" and one for the open file table named "files_struct." The C is a bit above my level, but it appears that the open file table is a files_struct that holds an fdtable (which in turn holds an array of fds), along with some state, safeguards, and limits. – labyrinth Jan 9 '15 at 21:01
  • Something like that. If you want tu understand UNIX/Linux system programming (not necessarily just kernel programming) then you'll definitely need to have reasonable understanding of C - reading the code helps, but for starters something smaller, e.g. a well written network daemon/client, might do you a better service. nc (sometimes called netcat) comes to mind as reasonably simple. – peterph Jan 10 '15 at 14:34

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.