linux关机相关命令

一、init 的运行级定义

1# init 0系统启动rc0脚本杀掉运行的进程,关闭操作系统。使用虚拟机测试关闭到关机状态;

2# init 1系统杀掉运行进程后启动到单用户模式。通过虚拟机测试可以看到虚拟机初始化到单用户模式,远程用户被out了。按Ctrl+Dexit)将设备重启,恢复到多用户状态;

3# init 5系统杀掉运行进程后,关闭操作系统。使用虚拟机测试,“然而并没有什么luan,没有出现关闭操作系统;

4# intit 6 重启。

二、shutdownpoweroffreboot命令

1shutdown在关机动作中用得比较多的命令。Shutdown主要会经过以下几个过程完成关机。

         1,指定关机时间,并发送消息给正在使用的用户;

         2,然后运行运行init 0杀掉所有进程;

         3,运行sync将内存中的数据同步到硬盘;

         4,最后调用halt进入关机模式;

2shutdown常用操作

         1,通过---help查看shutdown常用参数

[root@localhost ~]# shutdown --help
Usage: shutdown [OPTION]... TIME [MESSAGE]
Bring the system down.
Options:
 -r                          rebootafter shutdown
 -h                          haltor power off after shutdown
 -H                          halt after shutdown (implies-h)
 -P                        poweroff after shutdown (implies -h)
 -c                          cancela running shutdown
 -k                          onlysend warnings, don't shutdown
  -q,--quiet                 reduce output to errors only

         2,示例1

窗口1:[root@localhost ~]# shutdown 23:30 #直接加时间指明某刻关机。
Broadcast message from root@localhost
       (/dev/pts/2) at 22:56 ...
The system is going down for maintenance in34 minutes! #如果想取消也可以按Ctrl+C取消
shutdown: Shutdown cancelled  ##在另外一个终端使用-c参数取消了


窗口2:[root@localhost ~]#
Broadcast message from root@localhost
        (/dev/pts/2) at 22:56 ...
The system is going down for maintenance in34 minutes! #窗口1命令引起的消息
[root@localhost ~]# shutdown �Cc  #在另外一个终端使用-c取消


         3,示例2

[root@localhost ~]# shutdown 30  # The system is going down for maintenance in30 minutes!
[root@localhost ~]# shutdown -r now  # The system is going down for reboot NOW!

 

3halt命令

halt命令只完成关机进程的一部分职能,他不通报正在登陆的用户,不执行kill操作,而立即进行shutdown,如果使用#halt �Cq 会立即停止系统,没有同步,没有杀死进程或写入日志,非常危险。

[root@localhost ~]# halt
Broadcast message from root@localhost
       (/dev/pts/0) at 23:13 ...
The system is going down for halt NOW!

 

4poweroff 命令

Poweroff命令不通报正在登陆的用户,不执行kill脚本操作,立即进行shutdown并掉电。一般与sync命令同时使用如:#sync;reboot

 

三、总结:haltpoweroffreboot都是比较危险的操作,一般不建议使用这些命令。或者需要使用这些命令前先使用“sync”同步下。

使用shutdown时可以先是使用# shutdown now �Ck 只是发送关机消息,并不会真正的关机。


你可能感兴趣的:(linux,linux,虚拟机,linux,重启,关机,操作系统关机)