[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Commands Reference, Volume 5


telinit or init Command

Purpose

Initializes and controls processes.

Syntax

{ telinit | init } { 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | a | b | c | Q | q | S | s | M | m | N }

Description

The init command initializes and controls processes. Its primary role is to start processes based on records read from the /etc/inittab file. The /etc/inittab file usually requests that the init command run the getty command for each line on which a user can log in. The init command controls autonomous processes required by the system.

The process that constitutes the majority of the init command's process dispatching activities is /usr/sbin/getty. The /usr/sbin/getty process initiates individual terminal lines. Other processes typically dispatched by the init command are daemons and the shell.

The telinit command, which is linked to the init command, directs the actions of the init command. The telinit command takes a one-character argument and signals the init command by way of the kill subroutine to perform the appropriate action.

The telinit command sets the system at a specific run level. A run level is a software configuration that allows only a selected group of processes to exist. The system can be at one of the following run levels:

0-9 Tells the init command to place the system in one of the run levels 0-9. When the init command requests a change to run levels 0-9, it kills all processes at the current run levels and then restarts any processes associated with the new run levels.
0-1 Reserved for the future use of the operating system.
2 Contains all of the terminal processes and daemons that are run in the multiuser environment. In the multiuser environment, the /etc/inittab file is set up so that the init command creates a process for each terminal on the system. The console device driver is also set to run at all run levels so the system can be operated with only the console active.
3-9 Can be defined according to the user's preferences.
S,s,M,m Tells the init command to enter the maintenance mode. When the system enters maintenance mode from another run level, only the system console is used as the terminal.

The following arguments also serve as directives to the init command:

a,b,c Tells the init command to process only those records in the /etc/inittab file with a, b, or c in the run level field. These three arguements, a, b, and c, are not true run levels. They differ from run levels in that the init command cannot request the entire system to enter run levels a, b, or c.

When the init command finds a record in the /etc/inittab file with a value of a, b, or c in the run level field, it starts the process. However, it does not kill any processes at the current run level; processes with a value of a, b, or c in the run level field are started in addition to the processes already running at the current system run level. Another difference between true run levels and a, b, or c is that processes started with a, b, or c are not stopped when the init command changes run levels. Three ways stop a, b, or c processes:

  • Type off in the Action field.
  • Delete the objects entirely.
  • Use the init command to enter maintenance state.
Q,q Tells the init command to re-examine the /etc/inittab file.
N Sends a signal that stops processes from being respawned.

During system startup, after the root file system has been mounted in the pre-initialization process, the following sequence of events occurs:

  1. The init command is run as the last step of the startup process.
  2. The init command attempts to read the /etc/inittab file.
  3. If the /etc/inittab file exists, the init command attempts to locate an initdefault entry in the /etc/inittab file.
    1. If the initdefault entry exists, the init command uses the specified run level as the initial system run level.
    2. If the initdefault entry does not exist, the init command requests that the user enter a run level from the system console (/dev/console).
    3. If the user enters an S, s, M or m run level, the init command enters maintenance run level. These are the only run levels that do not require a properly formatted /etc/inittab file.
  4. If the /etc/inittab file does not exist, the init command places the system in the maintenance run level by default.
  5. The init command rereads the /etc/inittab file every 60 seconds. If the /etc/inittab file has changed since the last time the init command read it, the new commands in the /etc/inittab file are executed during system startup.

When you request the init command to change the run level, the init command reads the /etc/inittab file to identify what processes should exist at the new run level. Then, the init command cancels all processes that should not be running at the new level and starts any processes that should be running at the new level.

The processes run by the init command for each of these run levels are defined in the /etc/inittab file. The run level is changed by having a root user run the telinit command, which is linked to the init command. This user-run init command sends appropriate signals to the original init command initiated by the system during startup. The default run level can be changed by modifying the run level for the initdefault entry in the /etc/inittab file.

In the maintenance run level, the /dev/console console terminal is opened for reading and writing. The password for root is prompted. When the root password is entered successfully, the su command is invoked. Two ways exist to exit from the maintenance run level:

During a system startup attempt, apparent failure of the init command to prompt for a new run level (when initdefault is maintenance) may be due to the fact that the terminal console device (/dev/console) has been switched to a device other than the physical console. If this occurs and you wish to work at the physical console rather than the /dev/console, you can force the init command to switch to the physical console by pressing the DEL (delete) key at the physical console device.

When the init command prompts for a new run level, enter one of the digits 0 through 9 or any of the letters S, s, M, or m. If you enter S, s, M, or m, the init command operates in maintenance mode with the additional result that if control had previously been forced to switch to the physical console, the /dev/console file is switched to this device as well. The init command generates a message to this effect on the device to which the /dev/console file was previously connected.

If you enter a 0 through 9 run level, the init command enters the corresponding run level. The init command rejects any other input and re-prompts you for the correct input. If this is the first time the init command enters any run level other than maintenance, it searches the /etc/inittab file for entries with the boot or bootwait keywords. If the init command finds these keywords, it performs the corresponding task, provided the run level entered matches that of the entry. For example, if the init command finds the boot keyword, it boots the machine. Any special initialization of the system, such as checking and mounting file systems, takes place before any users are allowed on the system. The init command then scans the /etc/inittab file to find all entries that are processes for that level. It then resumes normal processing of the /etc/inittab file.

Run level 2 is defined by default to contain all of the terminal processes and daemons that are run in the multiuser environment. In the multiuser environment, the /etc/inittab file is set up so that the init command creates a process for each terminal on the system.

For terminal processes, the shell terminates either as a result of an end of file character (EOF) typed explicitly or as the result of disconnection. When the init command receives a signal telling it that a process has terminated, it records the fact and the reason it stopped in /etc/utmp file and /var/adm/wtmp file. The /var/adm/wtmp file keeps a history of the processes started.

To start each process in the /etc/inittab file, the init command waits for one of its descendant processes to stop, for a power fail signal SIGPWR, or until the init command is signaled by the init or telinit commands to change the system's run level. When one of the above three conditions occurs, the init command re-examines the /etc/inittab file. Even if new entries have been added to the /etc/inittab file, the init command still waits for one of the three conditions to occur. To provide for instantaneous response, re-examine the /etc/inittab file by running the telinit -q command.

If the init command finds that it is continuously running an entry in the /etc/inittab file (more than five times in 225 seconds), it assumes that an error in the entry command string exists. It then prints an error message to the console and logs an error in the system error log. After the message is sent, the entry does not run for 60 seconds. If the error continues to occur, the command will respawn the entry only five times every 240 seconds. The init command continues to assume an error occurred until the command does not respond five times in the interval, or until it receives a signal from a user. The init command logs an error for only the first occurrence of the error.

When the init command is requested to change run levels by the telinit command, the init command sends a SIGTERM signal to all processes that are undefined in the current run level. The init command waits 20 seconds before stopping these processes with the SIGKILL signal.

If the init command receives a SIGPWR signal and is not in maintenance mode, it scans the /etc/inittab file for special power fail entries. The init command invokes the tasks associated with these entries (if the run levels permit) before any further processing takes place. In this way, the init command can perform cleanup and recording functions whenever the system experiences a power failure. It is important to note that these power fail entries should not use devices that need to be initialized first.

Environments

Because the init command is the ultimate ancestor of every process on the system, every other process on the system inherits the init command's environment variables. As part of its initialization sequence, the init command reads the /etc/environment file and copies any assignments found in that file into the environment passed to all of its subprocesses. Because init subprocesses do not run from within a login session, they do not inherit a umask setting from init. These processes may set the umask to whatever value they require. A command that is executed by init from the /etc/inittab file uses init's ulimit values and not the default values as given in /etc/security/limits. The result is that a command that is successfully executed from the command line may not execute correctly when invoked by init. Any command that has specific ulimit requirements should include specific actions to set the ulimit values as required.

Examples

  1. To request the init command to reexamine the /etc/inittab file, enter:
    telinit q
  2. To request the init command to enter maintenance mode, enter:
    telinit s

Files


/etc/inittab Specifies the init command control file.
/etc/utmp Specifies the record of logged-in users.
/var/adm/wtmp Specifies the permanent login accounting file.
/sbin/rc.boot Specifies the pre-initialization command file.
/etc/rc Specifies the initialization command file.
/etc/environment Specifies system environment variables.
/dev/console Specifies the console device driver.

Related Information

The chitab command, lsitab command, mkitab command, rmitab command, getty command, rc command.

The inittab file, the rc.boot file.

The reboot subroutine, umask subroutine, ulimit subroutine, kill subroutine.


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]