What is the Linux kernel?
The Linux kernel is the main component of a Linux operating system (OS) and is the core interface between a computer’s hardware and its processes. It communicates between the 2, managing resources as efficiently as possible.
The kernel is so name because—like a seed inside a hard shell—it exists within the OS and controls all the major functions of the hardware, whether it’s a phone, laptop, server, or any other kind of computer.
What the kernel does
- Memory management: Keep track of how much memory is use to store what, and where
- Process management: Determine which processes can use the central processing unit (CPU), when, and for how long
- Device drivers: Act as mediator/interpreter between the hardware and processes
- System calls and security: Receive requests for service from the processes
So The kernel, if implemented properly, is invisible to the user, working in its own little world known as kernel space, where it allocates memory and keeps track of where everything is store. What the user sees—like web browsers and files—are known as the user space. In addition These applications interact with the kernel through a system call interface (SCI).
Think about it like this. The kernel is a busy personal assistant for a powerful executive (the hardware). Also It’s the assistant’s job to relay messages and requests (processes) from employees and the public (users) to the executive, to remember what is stored where (memory), and to determine who has access to the executive at any given time and for how long.
Where the kernel fits within the OS
To put the kernel in context, you can think of a Linux machine as having 3 layers:
- The hardware: The physical machine—the bottom or base of the system, made up of memory (RAM) and the processor or central processing unit (CPU), as well as input/output (I/O) devices such as storage, networking, and graphics. The CPU performs computations and reads from, and writes to, memory.
- The Linux kernel: The core of the OS. It’s software residing in memory that tells the CPU what to do.
- User processes: These are the running programs that the kernel manages. And User processes are what collectively make up user space. User processes are also known as just processes. The kernel also allows these processes and servers to communicate with each other (known as inter-process communication, or IPC).
Code executed by the system runs on CPUs in 1 of 2 modes: kernel mode or user mode. Code running in the kernel mode has unrestricted access to the hardware.While user mode restricts access to the CPU and memory to the SCI. A similar separation exists for memory (kernel space and user space). These 2 small details form the base for some complicated operations like privilege separation for security, building containers, and virtual machines.
This also means that if a process fails in user mode, the damage is limit and can be recover by the kernel. However, because of its access to memory and the processor, a kernel process crash can crash the entire system. Since there are safeguards in place and permissions required to cross boundaries, user process crashes usually can’t cause too many problems.
Linux kernel
The Linux kernel is the foundation of any Linux-base operating system. It represents the core of Linux distributions for servers and desktop computers. It’s also used in embedded systems, such as routers, and in all Android-based systems, including many popular tablets and smartphones. In essence, the Linux kernel is Linux. Operating systems such as Ubuntu, OpenSUSE, and Arch are sometimes refer to as “Linux” because they each use the Linux kernel.
The Linux kernel was created by Linus Torvalds in 1991 for use on his personal computer. Today, it is widely-adopted, free, and open source software that is actively maintained by developers all over the world. The Linux kernel is currently distributed under GNU‘s General Public License.
The Linux kernel is a “monolithic” architecture — the OS operates entirely in the kernel space. In contrast, in a microkernel architecture, the kernel alone defines and controls how the operating system interfaces with the computer’s hardware. Unlike standard monolithic kernels, the Linux kernel is also modular, accepting LKMs (Linux kernel modules) that act as device drivers. LKMs can be written, maintained, and distributed by device manufacturers or volunteers. And can load or unload to the system without rebooting, and without re-compiling the kernel.
Linux kernels support preemptive multitasking, virtual memory, shared libraries, memory management at the system level. Threading, and other modern operating system features. The default compiler for the Linux kernel is GCC.
Different Types of Kernels
There are, of course, different ways to build a kernel and architectural considerations when building one from scratch. In general, most kernels fall into one of three types: monolithic, microkernel, and hybrid. Linux is a monolithic kernel while OS X (XNU) and Windows 7 use hybrid kernels. Let’s take a quick tour of the three categories so we can go into more detail later.
Microkernel
A microkernel takes the approach of only managing what it has to: CPU, memory, and IPC. Pretty much everything else in a computer can be see as an accessory and can be handle in user mode. Microkernels have a advantage of portability because they don’t have to worry if you change your video card or even your operating system so long as the operating system still tries to access the hardware in the same way. Microkernels also have a very small footprint, for both memory and install space, and they tend to be more secure because only specific processes run in user mode which doesn’t have the high permissions as supervisor mode.
Pros
- Portability
- Small install footprint
- Small memory footprint
- Security
Cons
- Hardware is more abstracted through drivers
- Hardware may react slower because drivers are in user mode
- Processes have to wait in a queue to get information
- Processes can’t get access to other processes without waiting
Monolithic Kernel
Monolithic kernels are the opposite of microkernels because they encompass not only the CPU, memory, and IPC, but they also include things like device drivers, file system management, and system server calls. And Monolithic kernels tend to be better at accessing hardware and multitasking because if a program needs to get information from memory or another process running it has a more direct line to access it and doesn’t have to wait in a queue to get things done. This however can cause problems because the more things that run in supervisor mode, the more things that can bring down your system if one doesn’t behave properly.
Pros
- More direct access to hardware for programs
- Easier for processes to communicate between eachother
- If your device is support, it should work with no additional installations
- Processes react faster because there isn’t a queue for processor time
Cons
- Large install footprint
- Large memory footprint
- Less secure because everything runs in supervisor mode