The Linux kernel is like a bridge that enables computer communication between applications and hardware and manages system resources. Linus Torvalds developed the Linux kernel with C and Assembly and thus he succeeded in creating a light and portable kernel which was made public as open source.
You can see the Linux kernel in many different industries such as space, computers, smartwatches, mobile phones, robotics, and healthcare. But have you ever wondered how the Linux kernel works under the hood?
Using Hardware in Linux
The Linux kernel, first of all, controls what hardware will run and how when you turn on your computer. In addition, high-end software control is possible through the programming interface. To give an example of these controls, you can see information about the hardware installed in the slots of your motherboard and benefit from this detailed information.
In addition, this programming interface provides an abstraction layer. For example, if you want to have a video chat with your friends, you will need a webcam. The abstraction layer allows the software you are using to use this webcam regardless of its make and model. The software here can only use the interface that exists for Linux. The Linux kernel translates function calls from this interface into actual hardware commands that the webcam needs.
By using the /proc and /sys virtual file systems, the Linux kernel can export detailed information about the hardware it detects. Below you can see some tools used for this and what devices and maps they export:
- lspci: For PCI devices
- lsusb: For USB devices
- lspcmcia: For PCMCIA cards
As you can see, the Linux distribution in the screenshot above is running on VirtualBox. However, you have the option to see lots of information such as VGA, USB controller, bridges and SATA controller.
You can also use the -v parameter to get much more detailed information.
In the Linux kernel, applications generally access devices through special files that exist in the /dev phone book. These special files represent disk drives and other physical devices. Files such as /dev/hda, /dev/sdc, /dev/sdc3, /dev/input/mouse0 and dev/snd/* are examples of such special files.
Linux file system management
Filesystems are one of the most notable components of the Linux kernel. Linux’s file system is one of its greatest advantages. All files on a Linux system are collected in a single branch. Users can thus use this hierarchy to reach their desired places.
The starting point of this hierarchy is the root directory (/). The other subdirectories are under the root directory. The most used subdirectory under / is the /residence phone book. This subdirectory contains other subdirectories and each directory contains files that store the actual data.
For example, you can think of a text file on your desktop. If you create a text file called helloworld.txt on your desktop, you can refer to it as /home/muo/Desktop/helloworld.txt. The example of /muo here will of course vary. Because this subdirectory name depends on your current user name. With this naming system, the Linux kernel translates between real and physical storage that exists on a disk.
Additionally, the Linux kernel can integrate data from multiple disks. This is where the mounting system comes in. It uses one of the root system disks and mounts the others into existing directories in the hierarchy. The other disks are then placed under the mount points. This allows users to store /residence directory on a second hard drive that also contains other subdirectories.
When you mount a disk on the /residence directory, you can access these directories from normal locations. Thus, paths such as /home/muo/Desktop/helloworld.txt keep working.
You can see the mount points between files on your system with the find -A ordered.
With many file system formats, you can physically store data on disks. The best known under Linux are the ext2, ext3and ext4 file system formats. However, there are many other file system formats. In any case, you must format the filesystem before mounting it. You can use commands like mkfs.ext3 (mkfs stands for make file system and ext3 is file system) for that.
These commands accept the path of the device file you want to format as a parameter. This is a destructive operation and you should use it with caution if you don’t want to erase or reset a file system.
Apart from these, there are also network file systems such as NFS which the Linux kernel uses. NFS is a network file system in which data is not stored on a local disk. With NFS, data travels over the network to a server that stores the data. Since the data will be on a server, users won’t have to deal with it constantly. They can also use the traditional Linux hierarchical file system as usual.
Shared function operations
All Linux system software has common functions. This is why these functions are central to the Linux kernel. For example, when opening a file, you can open it with just the file name, without knowing where the file is physically stored or what functions and operations it will use. All these functions are already present in the kernel.
You can store your file on the hard drive, spread it across multiple hard drives, or even keep it on a remote server. Shared file communication features are important in such cases. Applications exchange data regardless of how the data is moved. Shared communication functions are there to carry out these data exchanges. This movement can be done over wireless networks or even over a fixed telephone line.
Linux process management
An active instance of a program operating on data or information in memory is called a process. The job of the Linux kernel is to generate and keep track of these memory regions. The kernel allocates memory for a running program and loads executable code into memory from the file system. Immediately after, the kernel executes the code.
The Linux kernel supports multitasking. It is able to run many processes at the same time. However, there is only one transaction in a given time frame. However, the Linux kernel divides the time into small chunks and therefore each procedure proceeds sequentially.
Because these small time segments are in millisecond increments, they are only active at specific times and remain inactive the rest of the time. The Linux kernel’s job here is to maximize performance by running multiple processes at once.
If the time slots are too long, the running application may not be as responsive as you would like. If the deadlines are too short, there may be problems with task changes. Depending on the priority of the process, the time interval required here will vary. You may have heard of high priority processes and low priority processes. It is one of the functions controlled by the Linux kernel.
This explanation is not always correct. The real limitation is that there can only be one worker process per CPU core at a time. Multiprocessor systems allow multiple processes to run in parallel. A basic system almost always has dozens of processes running.
Access rights under Linux
As with other operating systems, you can create many users on a Linux system. In such cases, there is a rights management system that supports individual users and groups. This is where file and user permissions come into play.
The Linux kernel manages the data and checks the necessary permissions for each process. For example, if you try to open a file, the kernel must check the process ID against the access permissions. If the kernel checks and sees that you have permissions, it will open the file.
The Linux kernel controls everything
As you can see, the Linux kernel oversees everything from keeping your files safe to creating users and downloading files from the internet. Everything is in a certain order. Each user has rights. The Linux kernel manages processes and timeslots for optimal performance.
In addition, the file system, which is one of the main characteristics that distinguishes the Linux kernel from other operating systems, is very important. Linux is not a hidden box. On the contrary, all files and source codes are accessible. To better understand the practical and powerful nature of the Linux kernel, you can examine the hierarchy of the Linux directory system.