The ancestor of all processes, called process 0 or, for historical reasons, the swapper process, is a kernel thread created from scratch during the initialization phase of Linux by the start_kernel( ) function (see Appendix A). This ancestor process uses the following data structures:
• A process descriptor and a Kernel Mode stack stored in the init task union variable. The init_task and init_stack macros yield the addresses of the process descriptor and the stack, respectively.
• The following tables, which the process descriptor points to:
o init mm o init fs o init files o init_signals
The tables are initialized, respectively, by the following macros:
O INIT_MM O INIT_FS O INIT_FILES O INIT_SIGNALS
• The master kernel Page Global Directory stored in swapper_pg_dir (see Section 2.5.5).
The start_kernel( ) function initializes all the data structures needed by the kernel, enables interrupts, and creates another kernel thread, named process 1 (more commonly referred to as the init process):
kernel_thread(init, NULL, CLONE_FS | CLONE_FILES | CLONE_SIGNAL);
The newly created kernel thread has PID 1 and shares all per-process kernel data structures with process 0. Moreover, when selected from the scheduler, the init process starts executing the init( ) function.
After having created the init process, process 0 executes the cpu_idle( ) function, which essentially consists of repeatedly executing the hlt assembly language instruction with the interrupts enabled (see Chapter 4). Process 0 is selected by the scheduler only when there are no other processes in the task_running state.
Was this article helpful?