The first process started, and stopped, on a Linux system is systemd.
What exactly is responsible for starting this process?
This isn't knowledge that will be assessed on the RHCSA exam, but
it's certainly something worthwhile knowing.
The Linux boot process is a complex sequence of events. It begins with the BIOS initializing the hardware and then transfers control to the bootloader. The bootloader loads the Linux kernel into memory, which subsequently initializes essential system components.
The Linux kernel does not care to the specific processes it executes. The first process to be launched is determined by the kernel's initial configuration and the bootloader. While the kernel provides the foundational environment for process execution, the choice of the first process is ultimately decided by the system's setup.
Systemd is Red Hat's child.
Once the kernel is operational, it spawns the initial user-space process, systemd. This systemd daemon assumes the role of orchestrating the remaining boot process. It mounts file systems, starts services, and brings the system to a fully functional state.
Ok, Little bit more explanation in depth about the Kernel boot process :
******The Linux boot process initiates with the BIOS, which prepares the hardware and transfers control to the bootloader. The bootloader then loads the Linux kernel into memory. This we know already, so we are goood here!
******Once loaded, the kernel begins its initialization phase. It detects memory layout, configures the CPU, and establishes the necessary data structures for protected mode operation.
******The kernel then decompresses itself and Paging is enabled, interrupt handler table is initialized and start_kernel() is called.
******start_kernel() / rest_init() and the subsequent called functions have the process id 0.
The kernel maintains at least one runnable process, often referred to as the idle task, swapper, init_task, or sched.
******The kernel's first process, with process ID 0, takes control and initializes various subsystems, including the task scheduler. It then spawns the kernel_init
process (PID 1), which is the ancestor of all user-space processes. Additionally, the kthreadd
process (PID 2) is created to manage kernel threads.
******The kernel_init
process handles tasks like mounting the root filesystem, loading device drivers, and eventually invoking the init
process (typically /sbin/init
).
******This init
process becomes the parent of all user-space processes and remains active throughout the system's runtime.
So, eventualy we came to know that first process started in Linux system is not PID 1 but PID 0.
PID 0 - definitely not something that will appear, even a single
mention, in the RH124, RH134, and/or RH294 courses. To tell
the whole truth, it doesn't get much publicity anywhere. However,
it's very real!
As Chetan so eloquently provided in his post, PID 0 is the first
process started in a Linux system. I'm going to add to this, that
PID 0 is not the first 'user-mode' process. The init process
(systemd) holds the honor of being the first user-mode process,
and owns PID 1 - and it is solely responsible for starting and
shutting down the system.
Repeating some of the things that Chetan provided, the process
with PID 0 is responsible for paging, and this process is always
referred to as the swapper or sched process. This process is a
part of the kernel and is not a regular user-mode process.
To provide a bit of a summary of the process that claiims PID 0:
In the Linux kernel, PID 0 refers to the "swapper" or "idle" process.
Some key points about PID 0 are:
Overall, PID 0 plays a vital role in the Linux kernel's process
management and scheduling mechanisms, ensuring efficient
CPU utilization.
Question to @Chetan_Tiwary_ Would it be appropriate, for your last two posts, to clarify 'BIOS' to actually mean 'Firmware, which could be legacy BIOS, or modern UEFI'?
Thank you.
R,
-Joe
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.