A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Shell Execution Model and Command Processing

College Depth 95 in the knowledge graph ☐ I know this ☆ Set as goal
36topics build on this
358prerequisites beneath it
See this on the map →
Process Creation: fork() and exec()Inter-Process Communication (IPC)→→Process Model Formalization
shell execution processes

Core Idea

The shell parses commands, applies expansions (wildcards, variables), handles redirection and pipes, and uses fork/exec to create child processes. Input redirection (<) and output redirection (>) modify the child's file descriptors before exec(). Pipes connect the stdout of one process to the stdin of another, enabling powerful composition and data flow between programs.

Explainer

You already understand that `fork()` creates a copy of the current process and `exec()` replaces that copy's code with a new program. The shell is the program that orchestrates this dance every time you type a command. When you enter `ls -l`, the shell does not run `ls` inside itself — it forks a child process, sets up that child's environment, and then calls `exec()` to replace the child with the `ls` program. The shell (parent) waits for the child to finish, then prints the next prompt. This fork-then-exec pattern is the heartbeat of every command you run.

What makes the shell powerful is what happens between fork and exec. After forking but before calling exec, the child process can modify its own file descriptors — and those modifications persist through the exec call. This is how redirection works. When you type `sort < data.txt > sorted.txt`, the shell forks, and the child process opens `data.txt` and connects it to file descriptor 0 (stdin), then opens `sorted.txt` and connects it to file descriptor 1 (stdout). Only then does the child exec into `sort`. The `sort` program has no idea its input and output were redirected — it just reads from stdin and writes to stdout as usual. The shell did all the wiring in advance.

Pipes extend this idea to chain processes together. When you write `cat log.txt | grep ERROR | wc -l`, the shell creates two pipes (each a pair of connected file descriptors), forks three child processes, and wires each one's stdin and stdout to the appropriate pipe ends. All three processes run concurrently — `cat` produces data, `grep` filters it, and `wc` counts lines — with the kernel buffering data in the pipe as needed. This compositional model lets you build complex data-processing pipelines from small, single-purpose tools without any of those tools needing to know about each other.

Before any of this happens, the shell also performs expansion: it replaces `*.txt` with matching filenames (globbing), substitutes `$HOME` with its value (variable expansion), and processes backticks or `$(...)` by running the enclosed command and inserting its output (command substitution). These transformations happen in the shell process itself, before fork, so the child process sees only the final, expanded arguments. Understanding this sequence — parse, expand, fork, redirect, exec — demystifies shell behavior and explains why quoting matters: quotes control which expansions the shell performs before handing arguments to the child program.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Boolean Algebra → Boolean Type and Truth Values → Comparison Operators and Boolean Tests → Logical Operators and Boolean Algebra → Boolean Algebra and Fundamental Laws → Logic Gates Fundamentals → Implementing Boolean Functions with Gates → Karnaugh Map Simplification → Combinational Circuit Design → Flip-Flops and Latches → Binary Counters: Design and Analysis → Binary Arithmetic → Fixed-Point Number Representation → Two's Complement Representation → Overflow and Underflow Detection → Binary Adders: Half-Adders and Full-Adders → Full Adder and Carry Propagation → Carry Lookahead Adder Design → Half Adder Circuit Design → Multiplication Circuit Design → Sequential Circuit Design → Registers and Register Files → Instruction Set Architecture (ISA) → Kernel Architecture and OS Structure → System Calls and User/Kernel Mode → Processes and the Process Control Block → Process Creation: fork() and exec() → Shell Execution Model and Command Processing

Longest path: 96 steps · 358 total prerequisite topics

Prerequisites (2)

Leads To (1)