正確的終端關閉方式是什麼?

正確的終端關閉方式是什麼?

我試著透過 SSH 關閉我的電腦。我執行了

sudo shutdown now

用戶已註銷,Ubuntu 開始關閉,但它凍結在帶有 Ubuntu 徽標和加載點的最後一個螢幕上。知道問題可能出在哪裡嗎?

shutdown另外,和之間有什麼差別halt?還有哪些類似的指令?

答案1

從手冊頁:

關閉- “關閉安排系統以安全的方式關閉。所有登入的用戶都會收到系統即將關閉的通知,並且在 TIME 的最後五分鐘內,將阻止新的登入。”這裡提到的時間是由使用者指定的關閉時間。

- “這些程式允許系統管理員重新啟動、停止或關閉系統電源。”

不同之處在於,Halt 在關閉時可能比 Shutdown 本身更「激進」。它的參數實際上可以強制系統關閉,而不考慮服務或開啟的程式。如果您不帶任何參數來執行halt,它將簡單地執行shutdown命令。類似別名之類的東西。例如,如果您使用參數運行它,--force它將“強制”系統非常快速地重新啟動。

在停止或關閉的情況下,它們將等待所有進程正確完成,然後再關閉電腦或重新啟動。如果服務或應用程式未關閉或未正確關閉,您將看到您在那裡提到的內容(帶有點的 ubuntu 標誌)。

對於單一用戶或多用戶來說,終端機中正確的方法是關閉。但是,如果關閉不起作用,請檢查您正在運行哪些服務以及哪一項導致關閉速度緩慢或凍結。

考慮到這一點,有幾種方法可以重新啟動或關閉系統:

重新啟動- shutdown -r,reboot

在這種情況下,重新啟動只是簡單地調用shutdown -r.

關閉- ,,,,,haltshutdownsudo init 0shutdown -h nowpoweroff

在這種情況下,poweroff與調用相同shutdown -P

正如您所注意到的,該shutdown命令可以執行很多操作,以下是其中的一小部分:

-r  Requests that the system be rebooted after it has been brought down
-h  Requests that the system be either halted or powered off after it has been brought down, with the choice as to which left up to the system
-H  Requests that the system be halted after it has been brought down
-P  Requests that the system be powered off after it has been brought down
-c  Cancels a running shutdown. TIME is not specified with this option, the first argument is MESSAGE
-k  Only send out the warning messages and disable logins, do not actually bring the system down

正如reboot

-f, --force                 force reboot or halt, don't call shutdown(8)
-p, --poweroff              switch off the power when called as halt

然而,透過終端關閉和點擊 Unity 中的「關閉」選項之間存在差異。後者將要求使用者與任何未儲存的工作進行互動(例如 libreoffice、inkscape...)。前者只會向所有行程發送一個訊號,告訴它們關閉。不需要用戶交互,因此任何未保存的工作都將消失。

答案2

您需要做的是透過執行以下命令在電腦關閉後關閉電腦電源:

sudo 關閉 -P 20

答案3

關閉系統的另一個命令是

sudo init 0

init 0 呼叫所有關閉腳本並正常關閉您的電腦。

答案4

建立一個腳本:

#!/bin/bash 
shopt -s nocasematch
read -t 30 -N 1 -p 'Shutdown now? (Y/n) '
[[ "$REPLY" =~ n ]] || sudo poweroff

相關內容