linux系统启动流程
时间:2008-11-17 来源:G_shenhai
When you start up your system, the first process called is init. Each process has a process identification number associated with it, called the PID. Because init is the first process, its PID is 1. The init process initializes the system and then starts other processes to open terminal lines and set up the standard input (stdin), standard output (stdout), and standard error (stderr), which are all associated with the terminal. The standard input normally comes from the keyboard; the standard output and standard error go to the screen. At this point, a login prompt would appear on your terminal.
After you type your login name, you will be prompted for a password. The /bin/login program then verifies your identity by checking the first field in the passwd file. If your username is there, the next step is to run the password you typed through an encryption program to determine if it is indeed the correct password. Once your password is verified, the login program sets up an initial environment consisting of variables that define the working environment that will be passed on to the shell. The HOME, SHELL, USER, and LOGNAME variables are assigned values extracted from information in the passwd file. The HOME variable is assigned your home directory, and the SHELL variable is assigned the name of the login shell, which is the last entry in the passwd file. The USER and/or LOGNAME variables are assigned your login name. A search path variable is set so that commonly used utilities may be found in specified directories. When login has finished, it will execute the program found in the last entry of the passwd file. Normally, this program is a shell. If the last entry in the passwd file is /bin/csh, the C shell program is executed. If the last entry in the passwd file is /bin/bash or is null, the Bash shell starts up. If the last entry is /bin/ksh or /bin/pdksh, the Korn shell is executed. This shell is called the login shell.
After the shell starts up, it checks for any systemwide initialization files set up by the system administrator and then checks your home directory to see if there are any shell-specific initialization files there. If any of these files exist, they are executed. The initialization files are used to further customize the user environment. At this point you may start up a windowing environment such as CDE, OpenWindows, or Gnome. A virtual desktop will appear and depending on the configuration, a console and some pseudo terminals displaying a shell prompt. The shell is now waiting for your input.