Systems study
Offline — showing the cached copy.
Home / Linux / 1. How a command becomes a process

1. How a command becomes a process

One-liner. The shell forks itself, execs the program, and waits for a status code.

Memorize

  • fork() duplicates the process (copy-on-write); execve() replaces its memory image with a new program.
  • The shell is a normal process; job control is just process groups plus terminal signals.
  • PID 1 (systemd) reaps orphans and runs as the ancestor of everything; it cannot be killed normally.
  • Every process has a parent, a process group, a session, and a controlling terminal.
  • $? is the exit status; 0 = success, 1–125 program-defined, 126 not executable, 127 not found, 128+n killed by signal n.
  • A zombie is exited but unreaped; an orphan is reparented to PID 1 (or a subreaper).
  • &, jobs, fg, bg, disown, nohup are job-control conveniences, not new mechanisms.
SHELL RUNNING A COMMAND Shell fork() child execve(cmd) runs wait() exit status shell
Shell running a command

Trap. Killing a process with kill <pid> when it ignores SIGTERM — kill sends TERM by default, which can be caught. Do this. kill -TERM, wait, then kill -KILL (SIGKILL cannot be caught or cleaned up).

Check

What does kill -9 <pid> guarantee that kill <pid> does not?