Tzafrir
Tzafrir

Reputation: 1849

In the linux kernel, where is the first process initialized?

I'm looking for the code in the linux kernel (2.4.x) that initializes the first process, pid=0.

Many searches provided many clues, but I still cannot find it.

Any pointers, anyone?

Upvotes: 5

Views: 7059

Answers (3)

Bandicoot
Bandicoot

Reputation: 3949

The first process that the kernel initializes is the swapper process or the idle thread. This thread runs forever. When no other process is active in the system, then this thread [which is cpu_idle() function found in arch/arm/kernel/process.c for the ARM architecture] calls the architecture dependent pm_idle function, which power collapses the CPU until a timer interrupt or some other interrupt wakes it up.

The swapper process [pid=0] is initialized in arch/arm/kernel/init_task.c by the macro INIT_TASK.

Upvotes: 1

caf
caf

Reputation: 239341

The initial task struct is set up by the macro INIT_TASK(), defined in include/linux/init_task.h. All other task structs are created by do_fork.

Upvotes: 11

dotjoe
dotjoe

Reputation: 26940

start_kernel()

check out rest_init() at the end

// idle process, pid = 0
cpu_idle();     // never return

Upvotes: 1

Related Questions