Linux关机命令

1 shutdown:

[NAME ]  shutdown - bring the system down

SYNOPSIS
       /sbin/shutdown [-t sec] [-arkhncfF] time [warning-message]

DESCRIPTION
       shutdown  brings  the  system  down  in a secure way.  All logged-in users are notified that the system is going down, and login(1) is blocked.  It is possible to shut the system down immediately or after a specified delay.   All  processes  are first  notified  that the system is going down by the signal SIGTERM.  This gives programs like vi(1) the time to save the file being edited, mail and news processing programs a chance to exit cleanly, etc.  shutdown does its job  by  signalling  the  init  process, asking it to change the runlevel.  Runlevel 0 is used to halt the system, runlevel 6 is used to reboot the system, and runlevel 1 is used to put to system into a state where administrative tasks can be performed; this is  the
       default  if  neither  the  -h  or  -r flag is given to shutdown.  To see which actions are taken on halt or reboot see the
       appropriate entries for these runlevels in the file /etc/inittab.

OPTIONS
       -a     Use /etc/shutdown.allow.

       -t sec Tell init(8) to wait sec seconds between sending processes the warning and the  kill  signal,  before  changing  to
              another runlevel.

       -k     Do not really shutdown; only send the warning messages to everybody.

       -r     Reboot after shutdown.

       -h     Halt after shutdown.

       -n     [DEPRECATED]  Do not  call init(8) to do the shutdown but do it ourself.  The use of this option is discouragedt.

       -f     Skip fsck on reboot.

       -F     Force fsck on reboot.

       -c     Cancel an already running shutdown. With this option it is of course not possible to give the  time  argument,  but
              you can enter a explanatory message on the command line that will be sent to all users.

       time   When to shutdown.

       warning-message
              Message to send to all users.

 

  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/reboot

   之所以将这两个命令写在一起的原因是 在linux下man halt 和man reboot都指向这个解释。

NAME
       halt, reboot, poweroff - stop the system.

SYNOPSIS
       /sbin/halt [-n] [-w] [-d] [-f] [-i] [-p] [-h]
       /sbin/reboot [-n] [-w] [-d] [-f] [-i]
       /sbin/poweroff [-n] [-w] [-d] [-f] [-i] [-h]

DESCRIPTION
       Halt  notes  that  the  system  is being brought down in the file /var/log/wtmp, and then either tells the kernel to halt,
       reboot or poweroff the system.

       If halt or reboot is called when the system is not in runlevel 0 or 6, in other words when it鈥檚 running normally, shutdown
       will be invoked instead (with the -h or -r flag). For more info see the shutdown(8) manpage.

       The rest of this manpage describes the behaviour in runlevels 0 and 6, that is when the systems shutdown scripts are being
       run.

OPTIONS
       -n     Do not sync before reboot or halt.

       -w     Do not actually reboot or halt but only write the wtmp record (in the /var/log/wtmp file).

       -d     Do not write the wtmp record. The -n flag implies -d.

       -f     Force halt or reboot, do not call shutdown(8).

       -i     Shut down all network interfaces just before halt or reboot.

       -h     Put all harddrives on the system in standby mode just before halt or poweroff.

       -p     When halting the system, do a poweroff. This is the default when halt is called as poweroff.

 

  其实halt就是调用shutdown -h。halt执行时﹐杀死应用进程﹐执行sync系统调用﹐文件系统 写操作完成后就会停止内核
   参数说明:
   [-n] 防止sync系统调用﹐它用在用fsck修补根分区之后﹐以阻止内核用老版本的超级块〔superblock〕覆盖修补过的超级块。
   [-w] 并不是真正的重启或关机﹐只是写wtmp〔/var/log/wtmp〕纪录。
   [-d] 不写wtmp纪录〔已包含在选项[-n]中〕。
   [-f] 没有调用shutdown而强制关机或重启。
   [-i] 关机〔或重启〕前﹐关掉所有的网络 接口。
   [-p] 该选项为缺省选项。就是关机时调用poweroff。

 

 

另转一篇区别:

http://blog.csdn.net/haijiaoyouzi/archive/2010/03/18/5394197.aspx

 

3 init命令

NAME
       init, telinit - process control initialization

SYNOPSIS
       /sbin/init [ -a ] [ -s ] [ -b ] [ -z xxx ] [ 0123456Ss ]
       /sbin/telinit [ -t sec ] [ 0123456sSQqabcUu ]

DESCRIPTION
   Init
       Init  is the parent of all processes.  Its primary role is to create processes from a script stored in the file /etc/init-
       tab (see inittab(5)).  This file usually has entries which cause init to spawn gettys on each line that users can log  in.
       It also controls autonomous processes required by any particular system.

 

Runlevels 0, 1, and 6 are reserved. Runlevel 0 is used to halt the system, runlevel 6 is used to reboot  the  system,  and
       runlevel  1  is used to get the system down into single user mode. Runlevel S is not really meant to be used directly, but
       more for the scripts that are executed when entering runlevel 1.

 

 init是所有进程的祖先﹐它的进程号始终为1﹐所以发送TERM信号给init会终止所有的用户进程﹑守护进程等。shutdown 就是使用这种机制。init定义了8个运行级别(runlevel),init 0为关机﹐init 6为重启。另外还有init命令可以改变init的运行级别﹐比如﹐init -1可使系统进入单用户模式。

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

惹不起的程咬金

来都来了,不赏点银子么

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值