[CALUG] How do I get out of X?

Dave Dodge dododge at dododge.net
Wed Aug 30 00:51:26 CDT 2006


On Sun, Aug 27, 2006 at 09:33:43PM -0400, Rajiv Gunja wrote:
> Again, I would have to say it is the other way around. init is the
> mother or parent of all programs. It was thought to be unwise to
> direct commands to it directly. So the programmers of Unix wrote a
> program called "telinit" to "tell" init what to do.

Here's some wild speculation as to how it went:

  - Originally there were very few things init needed to be able to
    do, and a few signals such as HUP and TERM would be sufficient to
    tell it to do those things.  No need for something like "telinit".

  - Then multiple runlevels were introduced, and the signals were no
    longer enough.  A protocol was designed to pass additional
    instructions to init, and "telinit" was created as a command-line
    way of performing that protocol.

  - Someone decides that the protocol stuff results in enough shared
    code between init and telinit that it's easier to just make them
    into a single executable.  This also has the advantage of being
    more efficient in both memory and disk accesses.  The executable
    now has to figure out at startup whether it's supposed to be
    running as "init" or "telinit".  In other such cases this is
    usually done by checking argv[0], but since init will always have
    PID 1 it's _much_ simpler and more reliable to just test for that.

  - People notice that the "init" program seems to be able to send
    commands to the init daemon, and start using "init" to do this.
    This behavior gets used here and there in scripts and example
    code, gets copied to other systems, etc.  From a human standpoint
    it's an easier way to do it since you only have to remember one
    command.  The behavior becomes ingrained.

The fact remains that it only works because init/telinit doesn't
bother to check argv[0] like other combined programs usually do.  You
could presumably run "telinit" with PID 1 and get the init daemon
behavior -- or give it a third name and use that likewise.

> The only times I remember using init was to make the server
> re-read its inittab file. (Q/q).

Note that "init" has no "q" command-line argument -- but "telinit"
does ;-)

Actually my immediate guess when wondering how to make it re-read its
config file is "kill -HUP 1", because HUP is traditionally used for
this in other Unix daemons.  Indeed this produces the "telinit q"
behavior on Linux.

                                                  -Dave Dodge


More information about the lug mailing list