Sep 9

Lecture Overview

One piece missing from our mental model of how the computer works is the operating system kernel. The kernel provides several basic features. The following is a highly simplified explanation but provides a good basic mental model of what happens.

Scheduling

Syscalls

The kernel also provides many standardized routines to processes called system calls or syscalls for short. Programs can take advantage of these routines by using an instruction to jump into the kernel. There are many different syscalls available:

The kernel can enforce security by limiting which syscalls a process can execute. For example, if only some processes are allowed to play sound, when some program syscalls into the kernel, the kernel can check if the process has permission before actually sending the sound data out to the sound card. Similarly, when a process syscalls into the kernel to access a file the permissions can be checked.

Memory Management

I've already hinted at it above, but the final major task the kernel is to be in charge of managing memory. The kernel keeps track of which process is using which piece of memory. A process can make a syscall into the operating system kernel asking for more memory and the kernel will find some unused memory and let the process know it can use it. The kernel is also in charge of protection to not allow one process to use another processes memory. This serves two purposes. First, it provides security so that the data like your bank password in one process cannot be accessed by another process. Second, this protects against bugs in one program taking out many other processes. If a process contains a bug (ok, more like when a process hits a bug since all programs have bugs) it might start writing to random locations in memory. If it writes into memory owned by a different process this will cause that process to malfunction. By protecting a process to only access its own memory, a bug in a single program just limits itself to that program.

The kernel enforces this protection via a complex mechanism called Virtual Memory which is outside the scope of this simple model I presented.

Exercises

No homework, but you could easily imagine several exam questions from the above material. For example, in 3-5 sentences explain what is a syscall.

It is not required for the course, but if you are interested, this book provides a nice introduction to operating systems. Not quite a textbook (the definitive textbook is this textbook), but Linux Kernel Development gives a good overview of an operating system. Despite its name, Linux Kernel Development is a good overview of all modern operating systems, not just Linux. It happens to use Linux as an example, but focuses on concepts.