2. shutdown程序
用戶從UNIX系統(tǒng)的啟動(dòng)過(guò)程中不難看到,系統(tǒng)在啟動(dòng)過(guò)程中啟動(dòng)了許多不同的進(jìn)程,許多文件被打開。在這種環(huán)境下,若所有的用戶需要退出系統(tǒng)或結(jié)束一個(gè)工作日,需要關(guān)閉UNIX系統(tǒng)時(shí)(即準(zhǔn)備關(guān)閉主機(jī)電源),千萬(wàn)不能關(guān)機(jī)了事。UNIX系統(tǒng)的不適當(dāng)關(guān)閉,將可能給UNIX文件系統(tǒng)造成意想不到的嚴(yán)重?fù)p害。關(guān)閉UNIX系統(tǒng)或關(guān)機(jī)操作必須嚴(yán)格按照UNIX系統(tǒng)管理規(guī)程的要求進(jìn)行。為確保系統(tǒng)數(shù)據(jù)和用戶數(shù)據(jù)的完整性,超級(jí)用戶在關(guān)機(jī)前,必須執(zhí)行專用的標(biāo)準(zhǔn)的關(guān)機(jī)程序——shutdown。
shutdown程序的描述是“terminate all processing”,其意為結(jié)束所有的進(jìn)程。所以,正確的關(guān)機(jī)方法是:(1) 如果root用戶是在主控臺(tái)上以普通用戶(非root用戶名)注冊(cè)的話,請(qǐng)用exit或按+鍵去注銷;(2) 以root為注冊(cè)名進(jìn)行注冊(cè)。在超級(jí)用戶環(huán)境下執(zhí)行shutdown程序。
語(yǔ)法格式:/etc/shutdown [-f file | mesg ] [ -g [hh:]mm ] [-i [0156sS ] ] [ -y ] [ su ]
shutdown程序選項(xiàng)說(shuō)明:
-f file 允許改變?nèi)笔〉木嫘畔。其中,警告的信息存?chǔ)在指定的文件file中。
-f mesg 允許改變?nèi)笔〉木嫘畔ⅰF渲,mesg信息部分須用雙引號(hào)括起來(lái)。
-g [hh:]mm 指示一個(gè)時(shí)間段,以小時(shí)和分鐘為單位;如果忽略了hh參數(shù),則以分鐘為單位(最大時(shí)間值為72小時(shí)),缺省值為1分鐘。該時(shí)間值指在關(guān)機(jī)前的等待時(shí)間,用戶接到該信息時(shí),系統(tǒng)已準(zhǔn)備停止運(yùn)行。
-i [0156abcsS] 指定系統(tǒng)的運(yùn)行級(jí)別。缺省值為0。使用-i1、-is、-iS都將使系統(tǒng)降為單用戶模式。
-y 表示關(guān)機(jī)過(guò)程中所有的詢問的對(duì)話都回答“yes”。
su 使用該選項(xiàng),將使系統(tǒng)從多用戶模式進(jìn)入到單用戶模式(系統(tǒng)不完全關(guān)閉)。
【例2-1】切換到單用戶模式之前1分鐘發(fā)送警告信息。
# /etc/shutdown –g1 –f”URGENT!! Wind up and logout NOW!!!” su å
Shutdown started.Tue May 23 23:09:27 CST 2000
Broadcast Message from root (tty01) on scosysv May 23 23:09: CST 2000 …
The system will be shut down in 60 seconds.
URGENT!! Wind up and logout NOW!!!
Please log off now.
Broadcast Message from root (tty01) on scosysv May 23 23:10 2000 …
THE SYSTEM IS BEING SHUT DOWN NOW 。!
Log off now or risk your files being damaged.
Do you want to continue?(y or n)_ y å
Shutdown proceeding,please wait ............
INIT:New run level:1
The system is coming down,please wait.
system services are now being stopped
cron aborted:SIGTERM
…
The system is down
INIT:New run level:S
INIT:SINGLE USER MODE
Type CONTROL-d to proceed with normal startup
(or give root password for system maintenance):_å
Entering System Maintenance Mode
Terminal type is scoansi
#_
系統(tǒng)從多用戶模式切換到單用戶模式的方法使用了su選項(xiàng)。進(jìn)入單用戶模式,root用戶可以進(jìn)行備份操作或其他系統(tǒng)維護(hù)工作。
【例2-2】在一定的時(shí)間后關(guān)閉系統(tǒng),給系統(tǒng)中的用戶以相應(yīng)的警告消息。
# /etc/shutdown –g3 -y –f”System to shutdown in 3 min!” å
Broadcast Message from root (tty01) on scosysv May 24 23:47 2000 …
The system will be shut down in 60 seconds.
System to shutdown in 3 min!
Please log off now.
Broadcast Message from root (tty01) on scosysv May 24 23:47 2000 …
THE SYSTEM IS BEING SHUT DOWN NOW 。!
Log off now or risk your files being damaged.
………
INIT:New run level:0
The system is coming down,please wait.
system services are now being stopped
cron aborted:SIGTERM
…
Stopping calendar server,please wait …
Calendar server stopped.
…
The system down.
** Safe to Power off **
- or –
** Press Any Key to Reboot **
到此,用戶可以關(guān)掉計(jì)算機(jī)的電源或按任一鍵重新啟動(dòng)系統(tǒng)。
3. haltsys命令
haltsys命令名來(lái)源于“halt system”,描述為“close out file systems and shut down the system”,其含義為停止文件系統(tǒng),關(guān)閉系統(tǒng)。該命令的功能特點(diǎn)是不事先通知系統(tǒng)中的用戶就立即使系統(tǒng)停止。如果在執(zhí)行haltsys命令時(shí)系統(tǒng)中還有用戶在工作,則這些用戶將被注銷,并且,他們的工作內(nèi)容將會(huì)失去,不進(jìn)行善后處理。所以,該命令只能是超級(jí)用戶在單用戶模式下使用。
語(yǔ)法格式:/etc/haltsys [-d]
【例2-3】haltsys命令的使用。
# haltsys å
** Safe to Power off **
- or –
** Press Any Key to Reboot **
【例2-5】使用init命令關(guān)閉系統(tǒng)。
# init 0 å
#
** Safe to Power off **
- or –
** Press Any Key to Reboot **
到此,用戶可以關(guān)掉計(jì)算機(jī)的電源或按任一鍵重新啟動(dòng)系統(tǒng)。