INIT(8) — MAINTENANCE COMMANDS
NAME
init − process control initialization
SYNOPSIS
/etc/init
DESCRIPTION
init is invoked inside UNIX as the last step in the boot procedure. It normally runs the sequence of commands in the script /etc/rc.boot (see rc(8)) to check the file system. If passed the −b flag from the boot program, init skips this step. If the file system check succeeds or is skipped, init runs the commands in /etc/rc and /etc/rc.local to begin multiuser operation; otherwise it commences single-user operation by giving the super-user a shell on the console. It is possible to pass the −s parameter from the boot program to init so that single-user operation is commenced immediately.
Whenever single-user operation is terminated (for instance by killing the single-user shell) init runs the scripts mentioned above.
In multi-user operation, init’s role is to create a process for each terminal port on which a user may log in. To begin such operations, it reads the file /etc/ttys and forks several times to create a process for each terminal specified in the file. Each of these processes opens the appropriate terminal for reading and writing. These channels thus receive file descriptors 0, 1 and 2, the standard input and output and the diagnostic output. Opening the terminal will usually involve a delay, since the open is not completed until someone is dialed up and carrier established on the channel. If a terminal exists but an error occurs when trying to open the terminal init complains by writing a message to the system console; the message is repeated every 10 minutes for each such terminal until the terminal is shut off in /etc/ttys and init notified (by a hangup, as described below), or the terminal becomes accessible (init checks again every minute). After an open succeeds, /etc/getty is called with argument as specified by the second character of the ttys file line. getty(8) reads the user’s name and invokes login(1) to log in the user and execute the shell.
Ultimately the shell will terminate because it received end-of-file, either explicitly, as a result of hanging up, or from the user logging out. The main path of init, which has been waiting for such an event, wakes up and removes the appropriate entry from the file utmp, which records current users. init then makes an entry in /usr/adm/wtmp, which maintains a history of logins and logouts. The wtmp entry is made only if a user logged in successfully on the line. Then the appropriate terminal is reopened and getty is reinvoked.
init catches the hangup signal (SIGHUP) and interprets it to mean that the file /etc/ttys should be read again. The shell process on each line which used to be active in ttys but is no longer there is terminated; a new process is created for each added line; lines unchanged in the file are undisturbed. Thus it is possible to drop or add phone lines without rebooting the system by changing the ttys file and sending a hangup signal to the init process: use "kill −HUP 1".
init terminates multi-user operations and resumes single-user mode if sent a terminate (TERM) signal: "kill −TERM 1". If there are processes outstanding which are deadlocked (due to hardware or software failure), init does not wait for them all to die (which might take forever), but times out after 30 seconds and prints a warning message.
init ceases creating new getty(8) processes, and allows the system to slowly die away, when sent a terminal stop (TSTP) signal: "kill −TSTP 1". A later hangup will resume full multi-user operations, or a terminate will initiate a single user shell. This hook is used by reboot(8) and halt(8).
init’s role is so critical that if it dies, the system will reboot itself automatically. If, at bootstrap time, the init process cannot be located, the system will loop in user mode at location 0x13.
DIAGNOSTICS
init: tty: cannot open. A terminal listed in the the /etc/ttys file cannot be opened, typically because the requisite lines are either not configured into the system or the associated device was not attached during boot-time system configuration.
WARNING: Something is hung (wont die); ps axl advised. A process is hung and could not be killed when the system was shutting down. This is usually caused by a process which is stuck in a device driver due to a persistent device error condition.
FILES
/dev/console, /dev/tty∗, /etc/utmp, /usr/adm/wtmp, /etc/ttys, /etc/rc
SEE ALSO
login(1), kill(1), sh(1), ttys(5), getty(8), rc(8), reboot(8), halt(8), shutdown(8)
BUGS
When coming up single-user, the system does not require the super-user to log in. To force a login when running single-user, add the line:
login root
to the file /.profile.
Sun Release 3.2 — Last change: 30 October 1983