- Linux 為多人多工環境,螢幕背後可能有多人或多個服務正在工作,不正常關機可能造成檔案系統毀損。
- sync:手動將緩衝於記憶體內的磁碟資料寫入磁碟。
- Linux 系統運作效率的考量,記憶體會暫存一些該寫入硬碟的資料。
- 正常的運作下,系統運作會視需要將資料回寫入硬碟。
- 該寫入硬碟的資料,有時還在記憶體中,等待回寫。因此,Linux 不能任意斷電關機。
- 正常的關機程序如 shutdown, reboot, halt 等指令都會呼叫特殊的 system call: sync, 來進行記憶體資料回寫的同步作業。以確保資料的正確。
- who:查看誰在線上。
[root@dywHome2 ~]# who
dywang tty1 2008-09-07 06:00
- ps -aux:查詢正在進行的程序。
- netstat -a:查看網路連線狀態。
- 正確關機指令:shutdown, poweroff, halt 及 reboot。
[root@dywOffice bin]# cd /sbin
[root@dywOffice sbin]# ll halt shutdown poweroff reboot
-rwxr-xr-x 1 root root 10540 Jul 2 2006 halt*
lrwxrwxrwx 1 root root 4 Mar 14 2007 poweroff -> halt*
lrwxrwxrwx 1 root root 4 Mar 14 2007 reboot -> halt*
-rwxr-xr-x 1 root root 18736 Jul 2 2006 shutdown*
- shutdown:通知線上使用者關機的時刻後關機。
[root@mdk-dyw ~]# shutdown
Usage: shutdown [-akrhfnc] [-t secs] time [warning message]
-a: use /etc/shutdown.allow
-k: don't really shutdown, only warn.
-r: reboot after shutdown.
-h: halt after shutdown.
-f: do a 'fast' reboot (skip fsck).
-F: Force fsck on reboot.
-n: do not go through "init" but go down real fast.
-c: cancel a running shutdown.
-t secs: delay between warning and kill signal.
** the "time" argument is mandatory! (try "now") **
[root@mdk-dyw ~]# shutdown -h now
[root@mdk-dyw ~]# shutdown -h 00:05
[root@mdk-dyw ~]# shutdown -h +30
[root@mdk-dyw ~]# shutdown -r now
[root@mdk-dyw ~]# shutdown -r +30 'The system will reboot'
[root@mdk-dyw ~]# shutdown -k now 'This system will reboot'
- halt:關機。
[root@mdk-dyw ~]# halt
- reboot:重新開機。
[root@mdk-dyw ~]# reboot