zoukankan      html  css  js  c++  java
  • Linux关机命令

    man shutdown:

    shutdown(8)                                                        shutdown(8)
    
    
    
    NAME
           shutdown - bring the system down
    
    SYNOPSIS
           shutdown [OPTION]...  TIME [MESSAGE]
    
    DESCRIPTION
           shutdown arranges for the system to be brought down in a safe way.  All
           logged-in users are notified that the system is going down and,  within
           the last five minutes of TIME, new logins are prevented.
    
           TIME  may  have  different  formats, the most common is simply the word
           'now' which will bring the system down immediately.  Other  valid  for‐
           mats  are  +m,  where m is the number of minutes to wait until shutting
           down and hh:mm which specifies the time on the 24hr clock.
    
           Once TIME has elapsed, shutdown sends a request to the  init(8)  daemon
           to bring the system down into the appropriate runlevel.
    
           This is performed by emitting the runlevel(7) event, which includes the
           new runlevel in the RUNLEVEL environment variable as well as the previ‐
           ous  runlevel  (obtained from the environment or from /var/run/utmp) in
           the PREVLEVEL variable.  An additional INIT_HALT variable may  be  set,
           this will contain the value HALT when bringing the system down for halt
           and POWEROFF when bringing the system down for power off.
    
    OPTIONS
           -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.
    
    ENVIRONMENT
           RUNLEVEL
                  shutdown  will  read  the current runlevel from this environment
                  variable if set in preference to reading from /var/run/utmp
    
    FILES
           /var/run/utmp
                  Where the current runlevel will be read  from;  this  file  will
                  also be updated with the new runlevel.
    
           /var/log/wtmp
                  A  new runlevel record will be appended to this file for the new
                  runlevel.
    
    NOTES
           The Upstart init(8) daemon does not keep  track  of  runlevels  itself,
           instead they are implemented entirely by its userspace tools.
    
           See runlevel(7) for more details.
    
     
    SEE ALSO
           runlevel(7) init(8) telinit(8) reboot(8)
    
    
    
    Upstart                           2009-07-09                       shutdown(8)

    1 我想立即关机!

    $shutdown -h now

    2 我想立即重启

    $shutdown -r now

    3 我想在23:30分准时关机

    $shutdown -h 23:30

    4 我想在15分钟后关机

    $shutdown -h +15

    5 总结一下,你可以看到,如果想让shutdown干活,你必须告诉shutdown命令一个时间,无论是now,还是23:30,还是+15。

    6 我想来个恶作剧!

    恶作剧,就是吓唬用户。这个功能其实很实用,如果你是管理员,你完全可以利用“恶作剧”提醒所有登录的用户,让他们尽快退出程序,你要关机了。

    来看看怎么搞“恶作剧”:

    $shutdown -k now “Server would shutdown in 15minutes!”

    看到了吧 加上-k选项就可以了 这样shutdown命令就知道这个命令只是一个恶作剧,不会真去关机的。shutdown会将你设定的消息字符串发给已登录的所有用户,这样就起到了提示的作用。试试-k吧!take it easy!

    over~

        在linux下一些常用的关机/重启命令有shutdown、halt、reboot、及init,它们都 
    可以达到重启系统的目的,但每个命令的内部工作过程是不同的,通过本文的介绍,希 
    望你可以更加灵活的运用各种关机命令。 
       1.shutdown 
       shutdown命令安全地将系统关机。 有些用户会使用直接断掉电源的方式来关闭linux, 
    这是十分危险的。因为linux与windows不同,其后台运行着许多进程,所以强制关机可能 
    会导致进程的数据丢失﹐使系统处于不稳定的状态﹐甚至在有的系统中会损坏硬件设备。 
        而在系统关机前使用shutdown命令﹐系统管理员会通知所有登录的用户系统将要关闭。 
    且login指令会被冻结﹐即新的用户不能再登录。直接关机或者延迟一定的时间才关机 
    都是可能的﹐还可能重启。这是由所有进程〔process〕都会收到系统所送达的信号〔signal〕 
    决定的。这让像vi之类的程序有时间储存目前正在编辑的文档﹐而像处理邮件〔mail〕和 
    新闻〔news〕的程序则可以正常地离开等等。 
        shutdown执行它的工作是送信号〔signal〕给init程序﹐要求它改变runlevel。 
    Runlevel 0被用来停机〔halt〕﹐runlevel 6是用来重新激活〔reboot〕系统﹐ 
    而runlevel 1则是被用来让系统进入管理工作可以进行的状态﹔这是预设的﹐假定没有-h也 
    没有-r参数给shutdown。要想了解在停机〔halt〕或者重新开机〔reboot〕过程中做了哪些 
    动作﹐你可以在这个文件/etc/inittab里看到这些runlevels相关的资料。 
       shutdown 参数说明: 
       [-t] 在改变到其它runlevel之前﹐告诉init多久以后关机。 
       [-r] 重启计算器。 
       [-k] 并不真正关机﹐只是送警告信号给每位登录者〔login〕。 
       [-h] 关机后关闭电源〔halt〕。 
       [-n] 不用init﹐而是自己来关机。不鼓励使用这个选项﹐而且该选项所产生的后果往 
    往不总是你所预期得到的。 
       [-c] cancel current process取消目前正在执行的关机程序。所以这个选项当然没有 
    时间参数﹐但是可以输入一个用来解释的讯息﹐而这信息将会送到每位使用者。 
       [-f] 在重启计算器〔reboot〕时忽略fsck。  
         [-F] 在重启计算器〔reboot〕时强迫fsck。 
       [-time] 设定关机〔shutdown〕前的时间。 
          
    2.halt----最简单的关机命令 
       其实halt就是调用shutdown -h。halt执行时﹐杀死应用进程﹐执行sync系统调用﹐ 
    文件系统写操作完成后就会停止内核。 
       参数说明: 
       [-n] 防止sync系统调用﹐它用在用fsck修补根分区之后﹐以阻止内核用老版本的超 
    级块〔superblock〕覆盖修补过的超级块。 
       [-w] 并不是真正的重启或关机﹐只是写wtmp〔/var/log/wtmp〕纪录。 
       [-d] 不写wtmp纪录〔已包含在选项[-n]中〕。 
       [-f] 没有调用shutdown而强制关机或重启。 
       [-i] 关机〔或重启〕前﹐关掉所有的网络接口。 
       [-p] 该选项为缺省选项。就是关机时调用poweroff。 
        
    3.reboot 
        reboot的工作过程差不多跟halt一样﹐不过它是引发主机重启﹐而halt是关机。它 
        的参数与halt相差不多。 
    4.init 
       init是所有进程的祖先﹐它的进程号始终为1﹐所以发送TERM信号给init会终止所有的 
       用户进程﹑守护进程等。shutdown 就是使用这种机制。init定义了8个运行级别(runlevel), 
       init 0为关机﹐init 1为重启。关于init可以长篇大论﹐这里就不再叙述。另外还有 
       telinit命令可以改变init的运行级别﹐比如﹐telinit -iS可使系统进入单用户模式﹐ 
       并且得不到使用shutdown时的信息和等待时间。  

    参考:http://fanqiang.chinaunix.net/a1/b1/20020130/21030661.html

  • 相关阅读:
    Makefile的常用技术总结
    NPOI 插入行[转]
    LINQ语句中的.AsEnumerable() 和 .AsQueryable()的区别 [转]
    Using Google Public DNS[Google公共DNS服务器]
    软件开发知识[TDD]
    MySQL函数之STRCMP()
    MySQL知识[INSERT语法]
    软件开发知识[ORM]
    软件开发知识[ADO.NET Entity Framework]
    mysql workbench 在模板与数据库间同步
  • 原文地址:https://www.cnblogs.com/youxin/p/3553185.html
Copyright © 2011-2022 走看看