How /sbin/init works

How /sbin/init works

  /sbin/init is the parent of all processes.Its primary role is to create processes from a script stored in the file /etc/inittab.This file ususally has entries which cause init to spawn gettys on each line that users can log in.It also controls autonomous processes required by any particular system.

  After init is invoked as the last step of the kernel boot sequence,it looks for the file /etc/inittab to see if there is an entry of the type initdefault.The initdefault entry determines the initial runlevel of the system.If there is no such entry(or no /etc/inittab at all),a runlevel must be entered at the system console.

# /etc/inittab: init(8) configuration.
# $Id: inittab,v 1.91 2002/01/25 13:35:21 miquels Exp $

# The default runlevel.
id:2:initdefault:

# Boot-time system configuration/initialization script.
# This is run first except when booting in emergency (-b) mode.
si::sysinit:/etc/init.d/rcS

# What to do in single-user mode.
~~:S:wait:/sbin/sulogin

# /etc/init.d executes the S and K scripts upon change
# of runlevel.
#
# Runlevel 0 is halt.
# Runlevel 1 is single-user.
# Runlevels 2-5 are multi-user.
# Runlevel 6 is reboot.

l0:0:wait:/etc/init.d/rc 0
l1:1:wait:/etc/init.d/rc 1
l2:2:wait:/etc/init.d/rc 2
l3:3:wait:/etc/init.d/rc 3
l4:4:wait:/etc/init.d/rc 4
l5:5:wait:/etc/init.d/rc 5
l6:6:wait:/etc/init.d/rc 6
# Normally not reached, but fallthrough in case of emergency.
z6:6:respawn:/sbin/sulogin

# What to do when CTRL-ALT-DEL is pressed.
ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now

# Action on special keypress (ALT-UpArrow).
#kb::kbrequest:/bin/echo "Keyboard Request--edit /etc/inittab to let this work."

# What to do when the power fails/returns.
pf::powerwait:/etc/init.d/powerfail start
pn::powerfailnow:/etc/init.d/powerfail now
po::powerokwait:/etc/init.d/powerfail stop

# /sbin/getty invocations for the runlevels.
#
# The "id" field MUST be the same as the last
# characters of the device (after "tty").
#
# Format:
#  <id>:<runlevels>:<action>:<process>
#
# Note that on most Debian systems tty7 is used by the X Window System,
# so if you want to add more getty's go ahead but skip tty7 if you run X.
#
1:2345:respawn:/sbin/getty 38400 tty1
2:23:respawn:/sbin/getty 38400 tty2
3:23:respawn:/sbin/getty 38400 tty3
4:23:respawn:/sbin/getty 38400 tty4
5:23:respawn:/sbin/getty 38400 tty5
6:23:respawn:/sbin/getty 38400 tty6

# Example how to put a getty on a serial line (for a terminal)
#
#T0:23:respawn:/sbin/getty -L ttyS0 9600 vt100
#T1:23:respawn:/sbin/getty -L ttyS1 9600 vt100

# Example how to put a getty on a modem line.
#
#T3:23:respawn:/sbin/mgetty -x0 -s 57600 ttyS3
  The inittab file describe which processes are started at bootup and during normal operation(e.g. /etc/init.d/boot,/etc/init.d/rc,gettys...).Init distinguishes multiple runlevels,each of which can have its own set of processes that are started.Valid runlevels are 0-6 plus A,B and C for ondemand entries.An entry in the inittab file has the following format:

        id:runlevels:action:process

  Lines beginning with '#' are ignored.

  id    is a unique sequence of 1-4 characters which identifies an entry in inittab.

        Note:traditionally,for getty and other login processes,the value of the id field is kept the same as the suffix of the corresponding tty,e.g. 1 for tty1.Some ancient login accounting programs might expect this,though I can't think of any.

  runlevels    lists the runlevels for which the specified action should be taken.

  action        describes which action should  be taken

  process      specifies the process tho be executed.If the process field starts with a "+" character,init will not do utmp and wtmp accounting for that process.This is needed for gettys that insist on doing their own utmp/wtmp housekeeping.This is also a historic bug.

  The runlevels field may contain multiple character for different runlevels.For example, 123 specifies that the process should be started in runlevels 1,2, and 3.The runlevels for ondemand entries may contain an A,B, or C.The runlevels field of sysinit,boot, and bootwait entries are ignored.

  When the system runlevel is changed,any running processes that are not specified for the new runlevel are killed,first with SIGTERM,then with SIGKILL.

  Valid actions for the action field are:

  respawn    the process will be restarted whenever it terminates(e.g. getty).

  wait          the process will be started once when the specified runlevel is entered and init will                   wait for its termination.

  once         the process will be executed once when the specified runlevel is entered.

  boot         the process will be executed during system boot.the runlevel field is ignored.

  off            this does nothing

 ondemand a process marked with an ondemand runlevel will be executed whenever the                  speicified ondemand runlevel is called.However, no runlevel change will occur.          (ondemand runlevels are 'a','b', and 'c').

initdefault  an initdefault entry specifies the runlevel which should be entered after system                  boot.If none exists,init will ask for a runlevel on the console.(Verified)

sysinit        the process will be executed during system boot.It will be executed before any boot                  or bootwait entires.The runlevels field is ignored.

powerwait   the process will be executed when the power goes down.Init is usually informed                   about this by a process talking to a UPS connected to the computer.Init will wait                  for the process to finish before continuing.

powerfail    As for powerwait,except that init does not wait for the process's completion.

powerokwait  this process will be executed as soon as init is informed that the power has been                  restored.

powerfailnow  this process will be executed when init is told that the battery of the external                      UPS is almost empty and the power is failing (provided that the external UPS and                      monitoring process are able to detect this condition.)

ctrlaltdel    the process will be executed when init receives the SIGINT signal.This means that                  someone on the system console has pressed the CTRL-ALT-DEL key                 combination.Typically one wants to execute some sort of shutdown either to get                  into single-user level or to reboot the system.

kbrequest   the process will be executed when init receives a signal from the keyboard handler                  that a special key combination was pressed on the console keyboard.

            


转载于:https://my.oschina.net/huihu/blog/189652

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值