Processes, fork & signals
Running a command means copying a process, then replacing what it is running.
Before you start
A **process** is a running instance of a program, identified by a number called the PID. Every command you run in the shell is a process; every browser tab, every server, every daemon.
The way Linux creates a new process is unusual: fork() makes a copy of the *current* process, and then exec() replaces that copy's program with a different one. So running ls is really "clone the shell, then have the clone turn into ls".
This lesson walks through fork + exec, shows a parent waiting for its child, and covers signals — the way one process can politely (or rudely) tell another to stop.
Processes
every process has a parentps -f shows this relationship: PID, PPID, and the command.
Step 1 of 8. Your shell is just a process. It has a process ID, and a parent process ID pointing at whatever started it — a terminal emulator or a login process. Every process except the very first has a parent, which makes the whole system a tree rooted at PID 1.
Step 01 / 08
Your shell is just a process
It has a process ID, and a parent process ID pointing at whatever started it — a terminal emulator or a login process.
Every process except the very first has a parent, which makes the whole system a tree rooted at PID 1.
ps -f # PID, PPID, commandsleep 60 & # run in the backgroundjobs # shells track background jobskill %1 # polite: SIGTERMkill -9 1234 # SIGKILL — cannot be caughtkill -STOP 1234 # pausekill -CONT 1234 # resume# a shell running a command:# fork() -> a copy of the shell# exec() -> that copy becomes the new program# wait() -> the shell waits for it to exit