Skip to content
Codescope

Processes, fork & signals

Running a command means copying a process, then replacing what it is running.

core10 min8 steps

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 parent
bashrunning
PID
2041
PPID
1990

ps -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.

01 / 08

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.

session.shShell
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