|     init是Linux系統開發執(zhi)行(xing)(xing)(xing)(xing)的第一個進程(cheng),進程(cheng)ID為1,是(shi)系(xi)統(tong)所(suo)(suo)有進程(cheng)的起點(dian),主要用來執(zhi)行(xing)(xing)(xing)(xing)一些開機初始(shi)化(hua)腳本和監(jian)視進程(cheng)。Linux系(xi)統(tong)在(zai)完成核內引導以后就(jiu)開始(shi)運行(xing)(xing)(xing)(xing)init程(cheng)序(xu),init程(cheng)序(xu)需要讀(du)取配置文件(jian)/etc/inittab。inittab是(shi)一個不可執(zhi)行(xing)(xing)(xing)(xing)的文本文件(jian),它由(you)若干行(xing)(xing)(xing)(xing)命令所(suo)(suo)組成。在(zai)RHEL 4系(xi)統(tong)中,inittab配置文件(jian)的內容如(ru)下所(suo)(suo)示(shi)。     ## inittab     This file describes how the INIT process should set up
 #            the system in a certain run-level.
 #
 # Author:     Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
 #            Modified for RHS Linux by Marc Ewing and Donnie Barnes
 #
 # Default runlevel. The runlevels used by RHS are:
 #   0 - halt (Do NOT set initdefault to this)
 #   1 - Single user mode
 #   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
 #   3 - Full multiuser mode
 #   4 - unused
 #   5 - X11
 #   6 - reboot (Do NOT set initdefault to this)
 #
 //表示當前缺省運行級別為5,啟動系統進入圖形化界面
 id:5:initdefault:
 //啟動時自動執行/etc/rc.d/rc.sysinit腳本
 # System initialization.
 si::sysinit:/etc/rc.d/rc.sysinit
 l0:0:wait:/etc/rc.d/rc 0
 l1:1:wait:/etc/rc.d/rc 1
 l2:2:wait:/etc/rc.d/rc 2
 l3:3:wait:/etc/rc.d/rc 3
 l4:4:wait:/etc/rc.d/rc 4
 //當運行級別為5時,以5為參數運行/etc/rc.d/rc腳本,init將等待其返回
 l5:5:wait:/etc/rc.d/rc 5
 l6:6:wait:/etc/rc.d/rc 6
 //在啟動過程中允許按[CTRL+ALT+DELETE]重啟系統
 # Trap CTRL-ALT-DELETE
 ca::ctrlaltdel:/sbin/shutdown -t3 -r now
 # When our UPS tells us power has failed, assume we have a few minutes
 # of power left.  Schedule a shutdown for 2 minutes from now.
 # This does, of course, assume you have powerd installed and your
 # UPS connected and working correctly.
 pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"
 
 # If power was restored before the shutdown kicked in, cancel it.
 pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"
 //在運行級別2、3、4、5上以ttyX為參數執行/sbin/mingetty程序,打開ttyX終端用于用戶登錄,如果進程退出則再次運行mingetty程序
 # Run gettys in standard runlevels
 1:2345:respawn:/sbin/mingetty tty1
 2:2345:respawn:/sbin/mingetty tty2
 3:2345:respawn:/sbin/mingetty tty3
 4:2345:respawn:/sbin/mingetty tty4
 5:2345:respawn:/sbin/mingetty tty5
 6:2345:respawn:/sbin/mingetty tty6
 
 //在級別5上運行xdm程序,提供xdm圖形方式登錄界面,并在退出時重新執行
 # Run xdm in runlevel 5
  x:5:respawn:/etc/X11/prefdm -nodaemon
     inittab配置(zhi)文件(jian)每行的基本格(ge)式(shi)如下。     id:runlevels:action:process     其中某些(xie)部分(fen)可以為(wei)空,下面我(wo)們逐一介紹。     1.id1~2個字符,配置行(xing)的惟一標識,在配置文件中(zhong)不能重復。
     2.runlevels配置行適用(yong)的運行級(ji)別,在這里可填(tian)入多個運行級(ji)別,比如12345或者35等。
     Linux有7個運行級別。● 0:關機。
 ● 1:單用戶字符界面。
 ● 2:不具備網絡文件系統(NFS)功能的多用戶字符界面。
 ● 3:具有網絡功能的多用戶字符界面。
 ● 4:保留不用。
 ● 5:具有網絡功能的圖形用戶界面。
 ● 6:重(zhong)新啟(qi)動系統(tong)。
     3.action     Init有如(ru)下幾(ji)種行為,如(ru)表1.1所示。                 表(biao)1.1                     init行為 
    
    | 行    為 | 描    述 |  
    | respawn | 啟動并監視第4項指定的process,若process終止則重啟它 |  
    | wait | 執行第4項指定的process,并等待它執行完備 |  
    | once | 執行第4項指定的process |  
    | boot | 不論在哪個執行等級,系統啟動時都會運行第4項指定的process |  
    | bootwait | 不論在哪個執行等級,系統啟動時都會運行第4項指定的process,且一直等它執行完備 |  
    | off | 關閉任何動作,相當于忽略該配置行 |  
    | ondemand | 進入ondemand執行等級時,執行第4項指定的process |  
    | initdefault | 系統啟動后進入的執行等級,該行不需要指定process |  
    | sysinit | 不論在哪個執行等級,系統會在執行boot及bootwait之前執行第4項指定的process |  
    | powerwait | 當系統的供電不足時執行第4項指定的process,且一直等它執行完備 |  
    | powerokwait | 當系統的供電恢復正常時執行第4項指定的process,且一直等它執行完備 |  
    | powerfailnow | 當系統的供電嚴重不足時執行第4項指定的process |  
    | ctrlaltdel | 當用戶按下【Ctrl+Alt+Del】時執行的操作 |  
    | kbrequest | 當用戶按下特殊的組合鍵時執行第4項指定的process,此組合鍵需在keymaps文件定義 |      4.process     process為(wei)init執行的進(jin)程(cheng)(cheng),這些進(jin)程(cheng)(cheng)都保(bao)存在(zai)目錄(lu)/etc/rc.d/rcX中,其中的X代(dai)表運(yun)行級別(bie),rc程(cheng)(cheng)序接收X參數,然后(hou)運(yun)行/etc/rc.d/rc.X下(xia)面的程(cheng)(cheng)序。使用如下(xia)命(ming)令可以(yi)查看/etc/rc.d目錄(lu)內容。     #ls -l /etc/rc.d/總用量 112
 drwxr-xr-x  2 root root  4096  3月 15 14:44 init.d
 -rwxr-xr-x  1 root root  2352 2004-03-17  rc
 drwxr-xr-x  2 root root  4096  3月 15 17:42 rc0.d
 drwxr-xr-x  2 root root  4096  3月 15 17:42 rc1.d
 drwxr-xr-x  2 root root  4096  3月 15 17:42 rc2.d
 drwxr-xr-x  2 root root  4096  3月 15 17:42 rc3.d
 drwxr-xr-x  2 root root  4096  3月 15 17:42 rc4.d
 drwxr-xr-x  2 root root  4096  3月 15 17:42 rc5.d
 drwxr-xr-x  2 root root  4096  3月 15 17:42 rc6.d
 -rwxr-xr-x  1 root root   220 2003-06-24  rc.local
 -rwxr-xr-x  1 root root 27411 2005-08-03  rc.sysinit
     使用如下命令查看/etc/rc.d/rc5.d的(de)內(nei)容(rong)。     # ls -l /etc/rc.d/rc5.d總用量 432
 lrwxrwxrwx  1 root root 21  4月 29 15:11 K01tog-pegasus -> ../init.d/tog-pegasus
 lrwxrwxrwx  1 root root 24  4月 29 14:20 K02NetworkManager -> ../init.d/NetworkManager
 lrwxrwxrwx  1 root root 17  4月 29 15:29 K02oddjobd -> ../init.d/oddjobd
 lrwxrwxrwx  1 root root 14  4月 29 15:31 K05innd -> ../init.d/innd
 lrwxrwxrwx  1 root root 19  4月 29 14:17 K05saslauthd -> ../init.d/saslauthd
 lrwxrwxrwx  1 root root 19  4月 29 14:21 K10dc_server -> ../init.d/dc_server
 lrwxrwxrwx  1 root root 16  4月 29 14:21 S09pcmcia -> ../init.d/pcmcia
 lrwxrwxrwx  1 root root 17  4月 29 14:17 S10network -> ../init.d/network
 lrwxrwxrwx  1 root root 16  4月(yue) 29 14:17 S12syslog -> ../init.d/syslog
     這(zhe)些文(wen)件都是符號鏈接,以(yi)S打(da)頭的(de)(de)(de)標(biao)(biao)識(shi)啟動該(gai)程(cheng)(cheng)序(xu),而(er)以(yi)K打(da)頭的(de)(de)(de)標(biao)(biao)識(shi)終止該(gai)程(cheng)(cheng)序(xu),后(hou)面的(de)(de)(de)數字標(biao)(biao)識(shi)執(zhi)(zhi)行(xing)(xing)順序(xu),越小越先執(zhi)(zhi)行(xing)(xing),剩下的(de)(de)(de)標(biao)(biao)識(shi)程(cheng)(cheng)序(xu)名。系統啟動或者切換(huan)到(dao)該(gai)運行(xing)(xing)級別時(shi)會執(zhi)(zhi)行(xing)(xing)以(yi)S打(da)頭的(de)(de)(de)程(cheng)(cheng)序(xu),系統切換(huan)到(dao)該(gai)運行(xing)(xing)級別時(shi)會執(zhi)(zhi)行(xing)(xing)以(yi)K打(da)頭的(de)(de)(de)程(cheng)(cheng)序(xu)。     這個目錄下(xia)的(de)(de)程序(xu)可通過chkconfig程序(xu)進行管理,當(dang)然(ran)這個目錄下(xia)的(de)(de)程序(xu)需要符(fu)合一定規范,如(ru)果(guo)了解shell編(bian)程,可以查看這些符(fu)號(hao)鏈(lian)接所指向(xiang)的(de)(de)程序(xu)的(de)(de)源碼。     init也是一個進(jin)程,和普通(tong)的(de)進(jin)程具有一樣的(de)屬(shu)性。比如修改(gai)了(le)/etc/inittab,想讓修改(gai)馬上生效(xiao),可通(tong)過(guo)運行“kill -SIGHUP 1”來實(shi)現,也可通(tong)過(guo)運行“init q”來實(shi)現。 華清遠見嵌入式linux視頻教程免費下載    熱點鏈(lian)接: 
         1、嵌入式linux驅動要學哪些2、嵌入式Linux串口編程基礎
 3、嵌入式Linux內核如何編譯
 4、Linux內核模塊程序結構
 5、典型嵌入式Linux系統設置
 
 更多新聞>>  |