3

When the init process is executed when the kernel has loaded, does it read the /etc/inittab file in a top down approach i.e. it executes each line as it appears in the file.

If so and based on my reading and understanding, does this mean that it enters the documented run level and then launch sysinit process or vice versa?

For example the common examples I have seen are

id:3:initdefault:

# System initialization.
si::sysinit:/etc/rc.d/rc.sysinit
PeanutsMonkey
  • 8,900
  • 36
  • 90
  • 133

2 Answers2

5

First, note that the format of inittab is like so:

Identifier:RunLevel:Action:Command

The key point here being the runlevel. Given the following example code:

a:3::
b:123::
c:23::
d:123::
e:23::

Then the order of execution of the various IDs, starting from runlevel 1 would be:

init 1:  b d
init 2:  c e
init 3:  a
overall: b d c e a

As you can see, it will run them in the order that they are listed in the file, group by runlevel! Also remember, if the identifier is not in the specified runlevel, it will be issued a SIGTERM and then a SIGKILL.

Andrew M.
  • 244
  • 1
  • 5
  • M - I don't quite follow why you would have multiple run levels for each identifier. – PeanutsMonkey Apr 11 '12 at 23:41
  • The runlevel says "only run the items specified for that runlevel." So for example, if I say `init 3` (move to runlevel 3), then `a` will start. If I say `init 2` (move to runlevel 2), then `a` will be killed because its not set to run at that runlevel. – Andrew M. Apr 12 '12 at 02:17
  • I take it when you say `items` you mean services or processes. Is that right? – PeanutsMonkey Apr 12 '12 at 19:02
  • Sorry, yes, I mean commands. – Andrew M. Apr 12 '12 at 23:22
  • What do you mean by `if the identifier is not in the specified runlevel, it will be issued a SIGTERM and then a SIGKILL`? – PeanutsMonkey Apr 17 '12 at 01:52
  • 1
    When you move from one runlevel to the next, if the specified command is not allowed, it will be issued a `SIGTERM` (which is a "Would you please end now? Thank you!") but, if it doesn't respond, will be issued a `SIGKILL`, which forcibly revokes the memory and process space. I _believe_ the average time is ~10 seconds, but most processes at that level will behave nicely. – Andrew M. Apr 17 '12 at 05:35
  • When you say `if the specified command is not allowed` what do you mean? – PeanutsMonkey Apr 26 '12 at 04:30
  • Think of the init daemon as simple defining different states of the machine. I.e., "this is the starting point for this operating system" at any given runlevel. [This link](http://www.linfo.org/runlevel_def.html) might give you a better understanding. – Andrew M. Apr 26 '12 at 06:35
  • @AndreM , but init 2 is supposed to execute b,c,d,e instead of only c,e ? I am asking because I can see runlevel 2 in those 4 places. – Lunar Mushrooms May 26 '13 at 03:31
  • 1
    @LunarMushrooms: No, because b and d have already been launched at runlevel 1. – Andrew M. May 30 '13 at 20:15
0

It is not a script that is processed in any particular order. It is a configuration file that tells the system what script/commands to run for a particular event or run level. The order of the entries in the file will make no difference, and you can have multiple scripts or commands for each run level.

the first line you show "id:3:initdefault:" tells the system the default run level is 3 => multiuser mode for most flavors.

the "si::sysinit:..." line tells the system to run the script /etc/rc.d/rc/sysinit upon system initialization (runs when the system boots).

if you man inittab, you should get a list of all the options for the file.

  • Yes but does that mean that it enters the run level first and then executes the /etc/rc.d/rc/sysinit file or does it execute the file first and then enters the run level followed by the corresponding run level scripts. – PeanutsMonkey Apr 12 '12 at 00:12