PHASE 01 · MODULE 02
Operating systems.
Every agent harness is a process supervisor. Most flaky shell tools come from misunderstanding pipes, process groups and terminals.
A process is a private address space plus a table of file descriptors. The kernel is the only way to touch anything outside it, and each crossing is a system call. Once you can see the system calls, most mysterious behaviour stops being mysterious.
Start lesson 1Basics
- Processes and threads
- fork and exec
- System calls
- File descriptors
- Pipes
- Signals
- Exit codes
- Environment variables
Depth
- Virtual memory and page faults
- mmap and the page cache
- Copy-on-write
- Scheduling
- PTYs
- Sessions and process groups
- Zombies and orphans
- PID 1 in containers
- The OOM killer
Current
- EEVDF scheduler (Linux 6.6+)
- sched_ext (Linux 6.12+)
- pidfd against PID reuse
- Landlock for unprivileged sandboxing
Lessons
- 01Processes and system callsA process is an address space, a set of open files and a thread or more of execution. The kernel boundary is where every outside effect happens.
- 02fork, exec, exit codes and environmentUnix creates a process in two steps: copy yourself, then replace the copy with a new program. Learn the steps, and what the exit status really carries.
- 03Pipes, buffers and EOFA pipe is a small kernel buffer with a reader and a writer. When nobody reads, the writer blocks. When anybody still holds the write end, the reader never sees EOF.
- 04Signals, process groups and orphansKilling a command means killing its whole tree. Learn process groups and sessions, why zombies appear, and what changes when your harness is PID 1.
- 05Terminals, PTYs and isattyPrograms behave differently when they think a person is watching. Learn what a pseudo-terminal is, and why
git loghangs in one harness and not another. - 06Virtual memory, page faults and the OOM killerEvery process sees its own clean address space. Behind it, the kernel maps pages lazily, shares them when it can, and kills someone when it runs out.
- 07Build a run_command tool that cannot hangPut the module together into the tool every coding agent needs, then see what Linux added in recent years to make it safer: pidfd, Landlock, EEVDF and sched_ext.
Module lab
- Write a small shell that supports pipes.
- Write a
run_commandtool with streamed stdout and stderr, a timeout, whole-tree kill, an output cap and an optional PTY. - Use
strace -fto watch what it really does.
Interview questions
Your agent's shell tool hangs sometimes. Walk me through the causes.
Full pipe, stdin or pager wait, a grandchild holding stdout, and a timeout that signals only the child.
Why does the same command print differently under a harness?
Programs call isatty and change colour, paging and buffering when stdout is a pipe.
What goes wrong when your app runs as PID 1 in a container?
Signal defaults differ, so SIGTERM may be ignored, and zombies are not reaped.
Read
- Operating Systems: Three Easy Pieces (free online)
- The Linux Programming Interface, Michael Kerrisk
- Man pages: pipe(7), pty(7), signal(7) and credentials(7)