linux下shutdown, halt, reboot的区别

原文:http://unix.stackexchange.com/questions/8690/what-is-the-difference-between-halt-and-shutdown-commands

http://askubuntu.com/questions/190202/difference-between-halt-and-shutdown-now



Generally, one uses the shutdown command. It allows a time delay and warning message before shutdown or reboot, which is important for system administration of multiuser shell servers; it can provide the users with advance notice of the downtime.

As such, the shutdown command has to be used like this to halt/switch off the computer immediately (on Linux and FreeBSD at least):

shutdown -h now

Or to reboot it with a custom, 30 minute advance warning:

shutdown -r +30 "Planned software upgrades"

After the delay, shutdown tells init to change to runlevel 0 (halt) or 6 (reboot). (Note that omitting -h or -r will cause the system to go into single-user mode (runlevel 1), which kills most system processes but does not actually halt the system; it still allows the administrator to remain logged in as root.)

Once system processes have been killed and filesystems have been unmounted, the system halts/powers off or reboots automatically. This is done using the halt or reboot command, which syncs changes to disks and then performs the actual halt/power off or reboot.

On Linux, if halt or reboot is run when the system has not already started the shutdown process, it will invoke the shutdown command automatically rather than directly performing its intended action. However, on systems such as FreeBSD, these commands first log the action in wtmp and then will immediately perform the halt/reboot themselves, without first killing processes or unmounting filesystems.

halt basically just calls shutdown -h and reboot runs shutdown -r. Note that if you pass the -f (force) option to halt or reboot, shutdown is not called



halt is not shutdown, they are different commands. The former does not turn the power off, unless -p option is used

From the manual (man halt): "-p, --poweroff : Instructs the halt command to instead behave as poweroff."

And, in your case, -p was not used in the haltcommand, hence your computer was not powered off.

Do not confuse this -p with the one from sudo, it's a different parameter for a different command. From man sudo:

  • -S The -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device. The password must be followed by a newline character.
  • -p prompt The -p (prompt) option allows you to override the default password prompt and use a custom one.

In your case, prompt is empty (no message displayed for sudo when asking password), and -S makes sudo accept root password vi stdin (so password may be supplied using pipes and redirection from other commands instead of being typed)



halt brings the system down to its lowest state, but leaves it powered on.

shutdown brings the system down to its lowest state, and will turn off power (soft power switch) if it can. Most computers now can do so.

reboot restarts the system. It brings the system down to its lowest state, then starts it up again.

Which to do depends on what you want to do. halt is usually to get to a state where you can perform low level maintenance. shutdown is to power the system off, and reboot is to reboot it.


其他参考:http://www.linuxforums.org/forum/slackware-linux/63551-halt-vs-shutdown.html---对于该话题的讨论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值