Your Program Is the Small Part of Your Process
Last timeThe Cost of Asking
A process is a pile of things the system holds for you: an address space, a table of open files, an identity, a set of handlers. Splitting one in two reveals exactly which parts are which.
The inventory
Ask what a process is and most answers are some version of a running program.
That is the least interesting part of the answer, because the program is a file
and the running is a scheduling decision. What makes a process a thing is
everything the kernel is holding on its behalf.
The list is worth reading slowly.
An address space, which is the mapping from the addresses your code uses to
actual memory. A table of open files. A user identity and a set of group
identities, which decide what it is allowed to do. A current working directory,
which is how relative names are resolved. A set of signal handlers and a set of
signals currently blocked. Any pending signals not yet delivered. Resource
limits. A scheduling priority and accumulated processor time. An identifier, a
parent, and a list of children. An exit status waiting to be collected once it
finishes.
Your code and data are one entry on that list. Everything else is bookkeeping
the kernel maintains because your program cannot maintain it itself, which is
the whole argument of the first lesson applied to a specific case.
What a file descriptor is
The second item on the list deserves its own treatment, because almost
everything confusing about processes turns out to be about it.
An open file in your program is a small integer. Zero, one, two for the
standard three, and then whatever comes next. That integer is not a handle in
the usual sense, it is an index into a table that belongs to your process. The
table entry points at something else: a shared object in the kernel describing
one open file, and critically, that object holds the current position.
That middle layer also explains why permissions behave as they do. The check
happens at open. After that, the descriptor is the authority, and it can be
passed to another process, inherited by a child, or kept across a complete
replacement of the program. A descriptor is a capability: holding it is
permission, and nobody rechecks how you got it.
The lesson stops here
5 more paragraphs to go
You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.
The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.
See the planThe contentsThis is the reading half
Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.
The contents