Chapter 1

What happens when you run a program

You type a word. You press Enter. Something happens. This chapter explains what, step by step, from the metal upwards.

A computer only follows instructions

Inside your machine is a chip called the CPU. It does all the thinking. Its job is simple, and it never changes:

That is all. The instructions are tiny. "Add these two numbers." "Put this number here." "If that number is zero, jump to a different instruction."

A CPU does this billions of times a second. That speed is the only thing that makes it feel clever. Each single step is very small.

The computer never guesses

It does exactly what it is told. Not what you meant. When a program does the wrong thing, the computer did not make a mistake — it followed your instructions correctly, and your instructions were wrong.

This is worth remembering. It is the whole reason bugs exist.

A program is a file of instructions

A program is a file. Inside it is a long list of those tiny instructions, saved on the disk, waiting.

The ls command you have been typing is a program. It is a real file, and you can look at it like any other file:

$ which ls
/usr/bin/ls
$ ls -l /usr/bin/ls
-rwxr-xr-x 1 root root 199464 Jan 23  2026 /usr/bin/ls

That number, 199464, is its size in bytes. About two hundred thousand bytes of instructions, sitting on your disk, so that you can list a folder.

Nothing about ls is special. It is a file, in a folder, like the files you made in step 1.5.

Disk keeps, memory works

Your machine has two places to put things, and they do different jobs.

DiskMemory
Also calledstorage, SSD, hard driveRAM
Speedslowvery fast
When power goes offkeeps everythingloses everything
Holdsyour files, and programs waitingprograms that are running now

Running a program means copying it from the disk into memory, and pointing the CPU at the first instruction. The CPU then works through the list.

A program sitting on the disk is just a file. The same program, copied into memory and being worked through, is called a process. One program can be running twice, as two processes, at the same time.

The CPU only understands numbers

Those instructions are numbers. The CPU knows nothing else. It cannot read printf or if or your variable names.

But people cannot write numbers all day. So we write words, and something turns our words into numbers. There are two ways to do that:

That single difference explains most of what feels different about C and Python. Chapter 7 comes back to it properly.

The operating system shares the machine

You have one CPU, but many programs want to run. Something must decide who gets a turn. That something is the operating system.

Its job is to:

Keeping programs apart matters. It is why one program crashing does not take the whole machine with it.

Windows is an operating system. Linux is another one. Ubuntu is a way of getting Linux, which chapter 3 explains.

The shell is a program that starts programs

Now the last piece. The shell is a program too. Its whole job is to start other programs for you.

When you type ls and press Enter, the shell:

  1. reads what you typed
  2. looks for a program with that name, and finds /usr/bin/ls
  3. asks the operating system to run it
  4. waits while it runs
  5. shows you the prompt again

That is the loop, over and over. Everything you do in a terminal is some version of it.

How the shell knows where to look

You typed ls, not /usr/bin/ls. The shell has a list of folders it searches, in order. That list is called PATH, and chapter 5 explains it.

It also explains the most common message a beginner sees: command not found. It rarely means the program is missing. It usually means the shell looked in its list and the program was not in any of those folders.

What the prompt is telling you

That $ is the shell saying: I am not busy. Type something.

While a program is running, there is no prompt. The shell is waiting, so it has nothing to say. When the program finishes, the prompt comes back.

This explains the "stuck" feeling

A student opens less or htop, and the prompt disappears. Nothing is broken and nothing is frozen. A program is running, and it will not give the terminal back until it ends.

Press q to ask it to finish, or Ctrl+C to ask the operating system to stop it. Then the prompt returns.

Try it

Find out where a command lives:

$ which ls

See that it really is a file, with a size:

$ ls -l /usr/bin/ls

Now watch the prompt go away and come back. This program does nothing for five seconds:

$ sleep 5

Run it again and press Ctrl+C before the five seconds are up. The prompt comes straight back, because you asked the operating system to stop the program early.

$ sleep 30

You can now explain