Course outline · 0% complete

0/28 lessons0%

Course overview →

Capstone: build a mini process inspector

lesson 9-2 · ~14 min · 28/28

Your turn to run the whole show

Time to touch every layer yourself, in one program. You will play the role of the shell:

  1. Create a program: write Python source code into a file on disk (unit 7).
  2. Inspect the file: read its metadata to prove it exists as bytes (lesson 7-3).
  3. Run it as a child process with subprocess, exactly how the shell does it (lesson 3-3).
  4. Capture what the child wrote to file descriptor 1 (lesson 8-2).
  5. Read its exit code and give a verdict (lesson 3-3).

First, run the working version below and match each print to the numbered step. Then extend it yourself in the exercise that follows.

Code exercise · python

Run the inspector. It writes a child program to disk, checks its size in bytes, runs it as a separate process, and reports its output and exit code.

Code exercise · python

Your turn. Inspect a FAILING program. Write bad.py containing exactly 'import sys\nsys.exit(3)\n', print its size on disk, run it, print the exit code, then print "verdict: ok" for code 0 or "verdict: failed" otherwise. Match the expected output exactly.

Where to go from here

You now hold the mental models that make the rest of a software career less mysterious:

  • A debugger pauses a process the same way the scheduler does, and reads its stack frames (unit 4).
  • Docker containers are ordinary processes wearing OS-enforced isolation, not tiny virtual machines.
  • Databases are careful choreography of buffers, fsync, and locks (units 5 and 7).
  • async/await is a user-space answer to the same problem the scheduler solves in unit 6: never waste time waiting.

When something weird happens, ask the course's questions: which process? whose memory? who is waiting on what? which layer buffered it? what did the exit code say? Those questions are the skill.

Quiz

Final check. Your inspector's child process crashes badly. Which statement about the parent inspector process is true, and which course idea guarantees it?