Categories
Linux Tutorial Series

Linux Tutorial Series – 4 – Zooming in on the kernel – what are its responsibilities?

Here is the video version, if you prefer it:

As described on page 4 in (Ward, 2014)⁠, the kernel, which is the core of the operating system, deals with the following four things:

  • Processes
  • Memory
  • Device drivers
  • System calls

Let’s look at each one in turn.

Proccesses

The kernel starts, pauses, resumes and terminates processes. The kernel is also responsible for giving processes the hardware they need to execute the thing they were programmed to do. That’s why we need hardware – we need hardware to actually perform the calculation the programmer intended it to do. The kernel decides which process gets what hardware at what time, as there are multiple processes running at the same time on the computer. For example, you most likely have a web browser open, as well as a File Explorer, as well as something else.

Memory

The kernel makes sure to:

  • give memory to a process
  • check if the process is only accessing its own memory and not some other processes memory
  • clean up the memory after the process terminates

When I say memory here, I mean RAM, that is, random access memory. Think of RAM as storage space – every program is stored in RAM as it is executed. The kernel makes sure to give each process enough RAM and to free up the RAM when the process terminates so other programs can “step in” the newly vacant storage space.

Why is it important for the process not to access other processes memory? Well, if it writes to some other processes memory, it could overwrite some data which may be really important for that process, which would be bad. There are other reasons, but since I am not a professional at information security at this point, I feel unqualified to talk about it.

Device drivers

The kernel manages the device drivers. Remember those things you have to install every time you install a new Windows on a computer that enable you to use some hardware (i.e. your speakers)? Well, two things about that. Number one, you (in most cases) don’t have to install drivers on Linux as they come preinstalled, so switch to Linux (subtle nudge into the Linux world, eh?). Number two, device drivers make it easy for programmers to talk to the hardware.

How is that? Let’s say I wanted to write some files to a hard disk. If I had a Samsung hard disk drive (HDD), and you had Seagate, the code for writing to Samsung HDD vs writing to Seagate HDD would most likely be different since they would have different hardware responsible for the task of writing to the HDD. Operating system allows me not worry about the details of the hardware. So instead of saying to the operating system “Write this to Samsung HDD” or “Write this to Seagate HDD” I just say “Write this to the HDD”. The operating system takes care of the specifics of the hardware.

System calls

System calls “call” the kernel to do something for them. For example, from my program (which is, let’s say, Firefox), I first tell the operating system to “write something to the HDD”. Then, the kernel takes over and writes it to the HDD for me and gives me some feedback on how did it go. Was it successful? Was it a failure? If it failed, why? Those are some things that the operating system handles for me.

In addition to this explanation, there are some terms frequently used when talking about process management. I list those in the References with relevant links if you are interested. Those are:

  • (“Timeslicing,” n.d.)⁠
  • (“Context switch,” n.d.)⁠

Hope this was useful!

References

Context switch. (n.d.). Retrieved April 7, 2020, from https://en.wikipedia.org/wiki/Context_switch

Timeslicing. (n.d.). Retrieved April 7, 2020, from https://en.wikipedia.org/wiki/Timeslicing

Ward, B. (2014). How Linux Works: What Every Superuser Should Know (2nd ed.). No Starch Press. Pages 4-8

NewsletterUpdates on interesting things I am doing

Subscribe to my newsletter to keep abreast of the interesting things I'm doing. I will send you the newsletter only when there is something interesting. This means 0% spam, 100% interesting content.

Leave a Reply

Your email address will not be published.