Tech●●●●●Difficulty 3 of 5

How does a program ask the kernel for something?

A program cannot even open a file by itself. It has to ring a bell, and the kernel decides whether to answer.

▶ Start the story

A program asks the kernel for something through a system call. A system call is the way a program requests a service from the operating system it runs on, such as reading a file, using the camera, or starting another program.

Why can't a program just do these things itself? Because the processor and the operating system keep programs in a box. A program is usually limited to its own , so it cannot touch other programs or the operating system, and it is usually prevented from directly manipulating hardware. Yet applications do need hardware, so the operating system offers system calls as well-defined, safe ways to ask.

Here is the trip. The program triggers a signal, often an . The interrupt puts the processor into an elevated and hands control to the kernel, which looks at the request and determines whether the calling program should be granted the service. If it is, the kernel runs its own instructions, which the program cannot see or change, then lowers the privilege level and returns control to the program.

One system call, step by step
  1. Step 1: Program asks

    For example: open this file

  2. Step 2:

    The processor rises to a higher

  3. Step 3: Kernel decides

    Is this program allowed to have it?

  4. Step 4: Kernel acts

    Runs its own instructions

  5. Step 5: Return

    Privilege lowered, control back to the program

Think of a bank counter. You never walk into the vault; you ask the teller, who checks you may have what you asked for, fetches it and slides it across the glass.

In daily life you never notice any of this. Programs usually reach system calls through a that sits between them and the operating system, so a programmer just writes "open this file" and the library does the knocking.

Quiz me

0/3

  1. 1.Why does a program use a system call to read a file instead of reading the disk itself?
  2. 2.What happens after a program triggers a system call by an interrupt?
  3. 3.What does a tool such as strace let you do?

Recap

A program never walks into the vault; it asks the teller, and the kernel decides.

💡 A trick to remember it · Teller behind the glass: you ask, the kernel checks your right, fetches the item, and slides it back.

Surprising fact · Linux has over 300 system calls and Windows close to 2000, while Plan 9 has only 54.

Sources (2)

No source, no claim. Every fact in this lesson (15 claims) cites at least one of these.

  1. [1]System call · Wikipedia
  2. [2]Kernel (operating system) · Wikipedia
More lessons in 💻 Tech (3) See all tech lessons →

One more light on your map.

Get one lesson like this every day, about the things you love. Free, in two or five minutes.

Get the share card for this lesson ↗