KernelNewbies
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

Kernel Hacking

  • Frontpage

  • Kernel Hacking

  • Kernel Documentation

  • Kernel Glossary

  • FAQ

  • Found a bug?

  • Kernel Changelog

  • Upstream Merge Guide

Projects

  • KernelJanitors

  • KernelMentors

  • KernelProjects

Community

  • Why a community?

  • Regional Kernelnewbies

  • Personal Pages

  • Upcoming Events

References

  • Mailing Lists

  • Related Sites

  • Programming Links

Wiki

  • Recent Changes

  • Site Editors

  • Side Bar

  • Tips for Editors

  • Hosted by WikiWall

Navigation

  • RecentChanges
  • FindPage
  • HelpContents

Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Comment

Revision 2 as of 2005-01-07 14:26:27
KernelNewbies:
  • InitTask

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:

time_init

Initialize system clock from CMOS

tty_init

Initialize the tty subsystem

trap_init

Initialize trap handlers (divide by zero, etc)

sched_init

Initialize the scheduler

buffer_init

Initialize the block device buffer system

hd_init

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:

setup()

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.

sync()

Synchronize I/O operations

_exit(0)

Terminate

  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01