Course contentsShow
← Linux
Lesson 280 of 1,8193. The Filesystem Hierarchy and POSIX StandardsFree lesson

File Descriptor Tables and Processes

Visualize the relationship between process file descriptors and global open file tables.

In this lesson, you will learn how the kernel manages the connection between a running process and the files it accesses by linking process-specific tables to a global shared record.

The Two-Tiered Architecture

When a process opens a file, the kernel doesn't just give the process a direct pointer to the file on the disk. Instead, it maintains a two-tier system to manage access.

  1. The Per-Process File Descriptor Table: Each process has its own private table. When you open a file, the kernel gives you a small integer (the "File Descriptor" or FD). This table acts like a local index; it maps an integer (like 3 or 4) to a specific entry in the global table.
  2. The Global Open File Table: This is a system-wide table maintained by the kernel. Each entry here tracks state information that is shared between processes, most importantly the current file offset (your "position" in the file).

Why the Split Matters

Imagine two processes opening the same file. Each process gets its own entry in its private FD table, but they both point to entries in the global table.

If two processes open the same file independently, they get separate entries in the global table. This means they each have their own independent "seek pointer." If one process reads 10 bytes, the other process’s position in the file remains unchanged.

However, if a process creates a child (via fork), the child inherits a copy of the parent's FD table. In this case, the entries point to the same global open file table entry. Consequently, if the parent moves its read pointer, the child sees that move too!

Process A Table        Global Open File Table       Inode (Disk)
[FD 3] ----------> [Entry 1: Offset 0] --------> [File Data]
[FD 4] ----------> [Entry 2: Offset 100] -------> [File Data]

By separating the "handle" (FD) from the "state" (global entry), the kernel allows processes to share access to files while keeping track of who is reading what, ensuring that multiple processes can coordinate their file interactions without stepping on each other's toes—unless they are specifically intended to share state.

Key Takeaway: A File Descriptor is just a local index that points to a shared kernel entry, which holds the critical state like the current read/write offset.