cancel
Showing results for 
Search instead for 
Did you mean: 
Trevor
Starfighter Starfighter
Starfighter
  • 1,780 Views

Question for future RHCSA Examinees

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.

 

Trevor "Red Hat Evangelist" Chandler
10 Replies
Chetan_Tiwary_
Community Manager
Community Manager
  • 1,698 Views

@Trevor great question! very important for Linux interview as well !

 

Trunx
Cadet
Cadet
  • 1,441 Views

I believe that is the kernel.

Trevor
Starfighter Starfighter
Starfighter
  • 1,402 Views

It is absolutely the kernel!!!!

Trevor "Red Hat Evangelist" Chandler
  • 1,403 Views

Isn't it the bootloader?

Trevor
Starfighter Starfighter
Starfighter
  • 1,402 Views

No ClariNerd617, it isn't the bootloader.

The bootloader is responsible for launching the kernel!

Many thanks for taking the time to provide a reply!!!!

Trevor "Red Hat Evangelist" Chandler
Chetan_Tiwary_
Community Manager
Community Manager
  • 1,384 Views

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.

Kernel takes extreme care here , so that pid 1 ends up being a system management daemon for obvious reasons ( right ?) , so much that if pid 1 exits, the KERNEL PANICS !!
Chetan_Tiwary_
Community Manager
Community Manager
  • 1,342 Views

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.

Chetan_Tiwary__0-1729892495451.png

 

******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).

Screenshot from 2024-10-26 03-07-08.png

******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.

Trevor
Starfighter Starfighter
Starfighter
  • 1,332 Views

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:

  1. Purpose: The idle process is responsible for managing
    CPU resources when no other processes are runnable.
    It runs when the system is idle, which means there are
    no other processes that need CPU time.
  2. Characteristics:
    - It has a PID of 0 and is created during the boot process.
    - It does not have a user-space representation; it exists
        entirely within the kernel.
    - It runs in a special state and is not associated with any
        user and does not perform any useful work.
  3. Scheduling: The idle process is scheduled by the kernel
    when there are no other processes ready to run. Its primary
    function is to keep the CPU busy in a low-power state or to
    perform minimal operations until a new process becomes
    runnable.
  4. Hierarchy: In terms of process hierarchy, the idle process
    is a child of the kernel, and is not directly visible to users in
    standard process listings - like those produced by the ps
    or top commands, 
    which will explain why it gets so little
    publicity..
  5. Role in System Performance: While PID 0 itself does not
    do any work, its efficient management is crucial for overall
    system performance and power management, especially in
    multi-core systems where the CPU can enter low-power
    states when idle.

Overall, PID 0 plays a vital role in the Linux kernel's process
management and scheduling mechanisms, ensuring efficient
CPU utilization.

 

Trevor "Red Hat Evangelist" Chandler
  • 59 Views

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

Join the discussion
You must log in to join this conversation.