Linux 0.01 init task.

Back to Kernel001WalkThrough.

This code is in Linux 0.01 init/main.c.

This code is a conventional ANSI-C main program called from ThirtyTwoBitInitialization.

Linus' comment at the head of this program points out that "forking from kernel space will result in NO COPY ON WRITE (!!!), until an execve is executed. This is no problem, but for the stack. This is handled by not letting main() use the stack at all after fork(). Thus, no function calls - which means inline code for fork too, as otherwise we would use the stack upon exit from 'fork()'."

main() performs the following tasks in order:


Initialize system clock from CMOS


Initialize the tty subsystem


Initialize trap handlers (divide by zero, etc)


Initialize the scheduler


Initialize the block device buffer system


Initialize the hard disk interrupt handler

Enable interrupts

Move to usermode

Fork a child to perform init()

Enter schedule loop

init() is a static function in main.c that goes like so:


Read hard drive partition tables.

fork a child to execute update(8)

Create the usual stdin,stdout,stderr file descriptors for console

Display a message indicating the number of buffers and the amount of buffer space available.

Fork a child to execute /bin/sh with argv[0]="-" and HOME=/usr/root

Wait for the child to die and print its exit code.


Synchronize I/O operations



KernelNewbies: InitTask (last edited 2017-12-30 01:30:08 by localhost)