閱讀863 返回首頁    go 阿裏雲 go 技術社區[雲棲]


深入理解linux下rc.d/目錄文件以及程序開機自啟動

由於我日常開發使用的是fedora9,所以,就已fedora9為例。

 

 [root@feiyinzilgd rc.d]# pwd /etc/rc.d [root@feiyinzilgd rc.d]# ls init.d rc0.d rc2.d rc4.d rc6.d rc.sysinit rc rc1.d rc3.d rc5.d rc.local

其中,x.d為目錄,其他的均為腳本可執行文件。

在講述這幾個目錄以及文件的作用及關係之前,我們需要了解linux(RedHat係列)的啟動順序。

係統上電之後,會進行硬件自檢,然後初始化啟動bootloader,加載內核,內核被加載到內存中之後,就開始運行啟動。一旦內核啟動,就可以初始化硬件設備,加載根文件係統。內核轉載根文件係統,初始化設備驅動以及相關數據結構之後,就會啟動一個init用戶級程序,完成引導進程。那麼,這個init進程就回去讀取/etc/inittab文件中的係統運行級別。

 

[root@feiyinzilgd rc.d]# cat /etc/inittab # inittab is only used by upstart for the default runlevel. # # ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM. # # System initialization is started by /etc/event.d/rcS # # Individual runlevels are started by /etc/event.d/rc[0-6] # # Ctrl-Alt-Delete is handled by /etc/event.d/control-alt-delete # # Terminal gettys (tty[1-6]) are handled by /etc/event.d/tty[1-6] and # /etc/event.d/serial # # For information on how to write upstart event handlers, or how # upstart works, see init(8), initctl(8), and events(5). # # Default runlevel. The runlevels used 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) # id:5:initdefault:

 

 

係統運行級別有0~6共7個運行級別:

 

# Default runlevel. The runlevels used 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) # id:5:initdefault:

 

#0 ——停機(不能使用)

#1——單用戶模式

#2——多用戶模式,但是沒有NFS

#3——完全多用戶模式

#4——沒有使用

#5——圖形界麵模式

#6——重啟模式(不能使用)

 

id:5:initdefault(運行模式設置)。

 

那麼,init進程就會讀取這個係統運行級別設置,然後運行/etc/rc.d/rc腳本。

 

通過這個腳本,然後進入rcx.d。啟動相應的程序。其中rcx.d為/etc/rc.d/rcx.d(x為對應的係統運行級別)

 

/etc/rc.d/rcx.d/下的文件均為符號鏈接,最終絕大部分都是都是鏈接到/etc/rc.d/init.d下麵。

到這裏,我們可以知道,/etc/rc.d/init.d目錄下麵的都是開啟啟動腳本文件,用來啟動相應的程序。

 


版權申明:
轉載文章請注明原文出處https://blog.csdn.net/feiyinzilgd/archive/2010/07/20/5750168.aspx

並請聯係譚海燕本人或者前往譚海燕個人主頁留言

最後更新:2017-04-02 06:51:20

  上一篇:go HttpHandler HttpModule入門篇
  下一篇:go wsprintf swprintf重要區別