Project 1: Minimal Command Executor

A program that reads commands from stdin and executes them using fork() and execvp(), displaying output and returning to the prompt.

Quick Reference

Attribute Value
Primary Language C
Alternative Languages Rust, Go, Zig
Difficulty Level 1: Beginner (The Tinkerer)
Time Estimate Weekend
Knowledge Area Operating Systems / Process Management
Tooling Unix Shell
Prerequisites Basic C, understanding of what a process is

What You Will Build

A program that reads commands from stdin and executes them using fork() and execvp(), displaying output and returning to the prompt.

Why It Matters

This project builds core skills that appear repeatedly in real-world systems and tooling.

Core Challenges

  • Understanding fork() (child gets copy of parent’s address space) → maps to process creation
  • Understanding exec() (replaces process image with new program) → maps to program loading
  • Parsing command and arguments (splitting “ls -la /tmp”) → maps to basic tokenization
  • Waiting for child termination (using wait() or waitpid()) → maps to process lifecycle
  • Handling exec failures (command not found) → maps to error handling

Key Concepts

  • fork() system call: “Advanced Programming in the UNIX Environment” Chapter 8 - Stevens & Rago
  • exec() family: “The Linux Programming Interface” Chapter 27 - Michael Kerrisk
  • Process creation model: “Operating Systems: Three Easy Pieces” Chapter 5 - Arpaci-Dusseau

Real-World Outcome

$ ./mysh
mysh> /bin/ls
file1.c  file2.c  mysh
mysh> /bin/echo hello world
hello world
mysh> /usr/bin/whoami
douglas
mysh> exit
$

Implementation Guide

  1. Reproduce the simplest happy-path scenario.
  2. Build the smallest working version of the core feature.
  3. Add input validation and error handling.
  4. Add instrumentation/logging to confirm behavior.
  5. Refactor into clean modules with tests.

Milestones

  • Milestone 1: Minimal working program that runs end-to-end.
  • Milestone 2: Correct outputs for typical inputs.
  • Milestone 3: Robust handling of edge cases.
  • Milestone 4: Clean structure and documented usage.

Validation Checklist

  • Output matches the real-world outcome example
  • Handles invalid inputs safely
  • Provides clear errors and exit codes
  • Repeatable results across runs

References

  • Main guide: SHELL_INTERNALS_DEEP_DIVE_PROJECTS.md
  • “Advanced Programming in the UNIX Environment” by W. Richard Stevens