System calls, Kernel, and init implementation in Linux

ยท

3 min read

System calls, Kernel, and init implementation in Linux

In this blog, we will the various system calls, init implementations, and work of the Kernel in Linux.

Let us start with how a computer starts or the Boot process of the system:

  1. BIOS - The BIOS or the basic input output system initializes hardware and makes sure that the hardware is good to go. It runs various checks on the hardware.
  2. Bootloader - The Bootloader loads the kernel into the memory based on kernel parameters. eg-GRUB bootloader.
  3. Kernel - The Kernel initializes the devices and memory in the system and then loads the init process.
  4. Init - It is the mother of all processes. Check out this blog for more info.

Now let us see the 3 different levels of abstraction -

  1. Hardware level- It includes the CPU, memory, ports, hard disk, etc.
  2. Kernel level - It is responsible for handling processes, system calls, and memory.
  3. User space level - All the things that we see on the screen come under this level.

Privileges of different levels / Protection rules

Among the different levels, the Kernel operates under kernel mode and the user operates under user mode. The Kernel always has the highest privileges to the hardware, it has all the access to the hardware that the user doesn't. The user only has access to a small amount of memory and CPU.

Let us take an example here - Imagine the hardware is the celebrity who is surrounded by her friends and bodyguards. In this case, it is not possible for the user to reach the celebrity. So how are we going to reach the celebrity?๐Ÿค”๐Ÿค”

For this, we need a VIP pass or in the sense of OS called System call or syscall.

The syscall usually provides user space with a way to request Kernel to get access to the system by something called the System call API.

Init process implementations

The 3 implementations of the init process in Linux are -

1. System V - It is the traditional way of implementation. In this implementation, the system starts and stops the process sequentially. One of the advantages of this process is it is easier to resolve dependencies issues. For eg - ps 1 and ps 2 are two processes in which ps 2 depends upon ps 1, it will make sure that processes start sequentially. However one of the disadvantages is that the performance is not great as parallel processing doesn't take place.

The status of the system is defined by the various run levels here i.e from 0-6 :

0- shutdown, 1- single user, 2-Multiuser without networking, 3-multiuser without networking, 4-System is idle unused, 5-multiple users are using through networking and GUI, 6-Rebooting

To check various run levels cmd is - ls /etc/rc0.d

To know the System V services cmd is - service --status-all

2. Upstart- This implementation was earlier used in Linux. It uses the events and jobs process. Jobs are the actions performed and events are the messages received from other processes that triggered the job.

3. System d - This system is the most recent implementation. It uses goals to get the system up and running. These goals have targets that they have to fulfill.

This system first loads up the config files. Config files are stored in either /etc/systemd directory else /lib/systemd/system directory.

These config files have many files with .target extensions, these targets are the goals, and one of them is the default.target. The default.target again has basic.target , like this it starts activating all those goals.

Like System V has various run levels here we have different target levels for different states -

  1. powerOff.target - shutdown
  2. user.target - For Single user
  3. Multiuser.target - For multiuser with networking
  4. graphical.target - For multiuser with networking and GUI
  5. reboot.target - rebooting

This blog is referenced from Linux Tutorials from Apoorv Goyal. You can follow this ๐Ÿ‘‰ link for a more detailed explanation. Like and follow for more content.๐Ÿ™Œ

ย