Bitpath

Lesson 2 · Unit 04

System calls

How programs ask the kernel for help

13 exercisesabout 3 min

What you practise

  • User mode and kernel mode, files/network/time go through the kernel, file descriptors, why a system call costs more than a function call, buffering

Try a question from this lesson

Pick one

A buggy program tries to write straight onto the disk hardware, across another program's files. What stops it?

The ideas

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

User mode and kernel mode

The CPU has two privilege levels. Your programs run in user mode. The kernel, the core of the OS, runs in kernel mode with full access to hardware.

A system call is how a program asks the kernel to do something for it: open, read, write, start a process.

your program          (user mode)
   |  write(fd, "hi")
===|=== system call ==============
   v
kernel                (kernel mode)
   '--> disk, network, screen

Concept

A system call is not a function call

A function call is a jump: about a nanosecond. A system call switches the CPU into kernel mode, has the kernel check the request, does the work and switches back. That often costs a hundred times more.

So programs avoid making many small system calls. They collect data in a buffer and hand it over in one go.

10 more exercises in the app

  • 4× multiple choice
  • 1× match the pairs
  • 2× type the answer
  • 1× fill the blanks
  • 1× true or false
  • 1× order the lines

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy