Home of the Guides to (mostly) Harmless Hacking Brought to you by... The website computer criminals don't want you to read!

Guides to (mostly) Harmless Hacking

Volume 5 Number 5:

Amit Rawat's Guides to Kernel Hacking, #1: Introduction to the kernel

What is a Kernel?

In the simplest of terms, a kernel can be thought of as a central component that provides basic services for every part of the operating system. It is the thing that loads first when your computer boots (obviously after the boot loader) and does memory management, process management, and device management. It acts as a bridge between your applications and the hardware.

Newbie note: We say a computer “boots up” from the old saying – a joke, really – “pull yourself up by your bootstraps.” A boot loader is the first software program that runs when a computer starts. The boot loader looks at the information in the BIOS (basic input/output system) chip on your motherboard in order to learn what hardware is available to it. Then it launches the kernel software, which the boot loader usually will have found on a hard drive.

The existence of a kernel can be attributed to the design of computer system as a series of abstraction layers, which rely on each other. So a kernel can also be termed as the lowest level of the abstraction implemented in the software.

Newbie note: What the heck are abstraction layers? You could think of abstraction layer5s as being like levels of a tall office building. The boot loader is the very bottom of the foundation of this building, the base upon which all else depends. The kernel is the rest of the foundation, sitting on the boot loader and it underlies all else in this building. Other abstraction layers are more like towers and wings of a building. They all depend upon the kernel but they don't all pile up in a single stack of layers.

Why is a kernel essential?

A kernel becomes an absolute necessity – the foundation for all software running on your computer – as it performs critical related-to-hardware functions, which can mainly be divided as:

i) Memory Management

Memory here refers to the RAM (random access memory) installed on the users system and is used to store instructions and data related to a program. It is the part where an application is loaded before it is executed. The kernel manages memory between different processes and is responsible for how much memory a process can use. If the memory installed on a users system is not sufficient to hold the number of running processes, the kernel decides what to do (like allocating 'virtual memory for idle processes or switching memory from RAM to a hard drive and back into RAM.

Newbie note: RAM is contained on one or more chips on your motherboard. Your computer runs much faster when it is using only RAM instead of moving memory onto and off of a hard drive.

ii) Process Management

The kernel is also responsible for managing the CPU (central processing unit) between the different applications.

Newbie note: There is a chip on your mother board that holds one or more processing units. For example, a “dual core” CPU actually holds two processing units. Nowadays all CPUs also contain some memory, and because this memory is on the same chip with the CPU it is even faster than RAM. This is why some people are willing to pay much more for a CPU chip that has a large amount of memory on the chip. Depending upon how the kernel is designed, your computer might be about to use dozens of processing units. That is an advantage of some Linux kernels. Windows, by contrast, can't make much use of more than four processing units on a single computer.

The kernel decides about how the running applications must be allocated to the processor(s) as a processor usually supports one process at a time (multi threading processors are an exception to this rule), but the kernel may also behave as if it is running more threads that a computer is physically able to support, a term more commonly known as multitasking. The kernel decides which processes to run and for how much time using a scheduling algorithms, the discussion of which is out of this guide's scope.

Newbie note: Your computer seems as if it is running many processes at once, but in reality each of its processors take turns running them so fast you usually won't notice it. For example, as I write this Newbie Note, my computer is running a word processor, keeping up an Ethernet connection through a router to the Internet, and is running the Chrome browser which I am using to look things up for this Guide. The kernel manages all this swapping back and forth among tasks.

iii) Device Management

The applications need the peripherals attached to a system for various types of features it may provide, like printing, displaying etc. The kernel controls all the devices using device drivers, if a particular device driver is missing the kernel is unable to provide you the services that the device provides.

The kernel may know all the devices attached in advance (embedded systems), or it may auto detect them (plug and play, which is the standard in use today), or sometimes you might have to configure it yourself (non plug and play).

Next: Kernel Bloat --->>

Next: Memory Management --->>




Google Groups
Subscribe to Happy Hacker
Visit this group
Privacy policy      © 2013 Happy Hacker