Processes and system calls
A 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.
When you run a program, the kernel creates a process: a private virtual address space holding code, data, heap and stack; a table of file descriptors; credentials such as user ID; and one or more threads that execute instructions. Threads in one process share memory and descriptors. Separate processes share nothing unless they set it up explicitly.
What a process owns
File descriptors: everything is a number
Descriptors 0, 1 and 2 are stdin, stdout and stderr by convention. open, socket and pipe hand out the lowest free number. A descriptor is a reference to a kernel object, and several descriptors in several processes can refer to the same object. That sharing is how pipes connect programs, and, as you will see, how pipes fail to close.
System calls
User code cannot touch hardware. To read a file, it calls read(fd, buf, n), which switches the CPU into kernel mode, does the work, and returns. A system call costs from about a hundred nanoseconds to microseconds, which is why buffered I/O exists: one write of 64 KB beats 65,536 writes of one byte.
# Every system call 'cat' makes, with arguments and results
strace -f -e trace=openat,read,write,close cat /etc/hostname
# On macOS, the closest equivalent needs SIP adjustments:
# sudo dtruss -f cat /etc/hostname
# List a running process's open descriptors
ls -l /proc/$PID/fd # Linux
lsof -p $PID # Linux and macOSstrace -f follows children too, which is what you want when debugging a shell tool.
Where you will meet it
Claude Code, Codex and similar tools run shell commands as child processes and stream their stdout and stderr back to the model.
A server that opens files or sockets without closing them hits EMFILE: too many open files at the ulimit -n limit, often 1,024 by default.
strace -p PID on a stuck process shows the exact system call it is blocked in, usually read, write, wait4 or futex.
Check yourself
Answer out loud before you open each one.
What do threads in one process share that separate processes do not?
The address space and the file descriptor table.
Why is writing one byte at a time slow?
Each write is a system call with fixed overhead. Buffering amortises it over many bytes.
What is file descriptor 2?
stderr, by convention.
Try it
Run strace -f -c node -e 'require("fs").readFileSync("/etc/hosts")' on Linux. The -c summary counts every system call Node makes just to start and read one file.