Linux System Programming · advanced · ~20 min
Combine `fork`, `exec`, and `wait` to build a tiny REPL shell. (A REPL is a Read-Eval-Print Loop: read input, run it, show the result, repeat.)
A shell repeats the same four steps over and over:
argv (an array of argument strings).fork + exec to launch the requested program.wait for that program to finish.A usable subset fits in about 60 lines of C. "Subset" here means the basics only: no pipes (|) and no redirections (>, <).
Writing a mini shell is the classic rite of passage for Linux systems programming. It ties together three core ideas:
fork — the split into a parent process and a child process.exec — replacing the child's program image with a new one.wait / exit — the contract by which a parent collects a child's exit status.argv array you pass to exec must be NULL-terminated, or exec will read past the end of the array.