Lion Cipher Lab

Write a Unix shell from scratch (fork, exec, pipes, and redirection)

Why it matters

A shell feels like magic until you write one, and then it becomes the most demystifying program you will ever build. Every command you have ever typed — `ls`, `grep`, `python`, a pipeline, a redirect — is the shell making a tiny handful of syscalls on your behalf: fork to make a new process, exec to become the program you asked for, wait to collect its exit status, pipe and dup2 to wire programs together, open to redirect a file, and signal handling so Ctrl-C hits the right process. Those same syscalls are the foundation the rest of the corpus stands on: strace exists to SHOW you the…

What you'll learn

Steps in this lab

  1. What a shell actually is: the fork / exec / wait loop
  2. Set up a scratch box and the skeleton
  3. The REPL core: fork + execvp + waitpid + two built-ins
  4. Why cd and exit MUST be built-ins (and cannot be forked)
  5. I/O redirection: open + dup2, and closing the original fd
  6. The pipeline a | b: pipe + dup2, and closing BOTH ends everywhere
  7. Signals: why the shell ignores Ctrl-C but the child doesn't
  8. Break it on purpose #1: create a zombie (forget to wait)
  9. Break it on purpose #2: the classic pipe deadlock (fd leak)
  10. The judgment: where your shell sits, and the next rungs

Open the full interactive lab →