Linux 正常关机

jwb*_*ley 21 linux

我听说“shutdown -h now”不是一个优雅的关闭命令,因为它对所有进程执行类似于“kill -9”的操作,而不是“kill -15”。

这是真的吗,如果是这样,有什么更优雅的关闭方式来确保一切都有时间自我清理?

Ps 主要使用 CentOS、Ubuntu 和 Debian。

Cak*_*mox 15

shutdown -h now将调用/etc/rc.d/rc/etc/init.d/rc。该rc脚本将调用新运行级别的终止脚本(0 代表-h,6 代表-r),然后是任何启动脚本。

根据您的发行版,您会看到S30killprocsS00killall类似的东西。这是在调用所有终止脚本以尝试依次优雅地停止每个服务之后发生的。它将kill -15首先尝试,然后是kill -9

简短的回答:shutdown -h now或者shutdown -r now是优雅的。 halt并且reboot曾经是不优雅的,但shutdown除非您使用该-f选项,否则他们只会打电话给您。


mai*_*ilq 13

不,那不是真的。shutdown更改 init 级别,然后运行所有关闭脚本。这些脚本做什么取决于脚本。但它们通常不会终止进程,而是向它们发送结束信号。

所以这是手册摘录shutdown

   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.
Run Code Online (Sandbox Code Playgroud)

  • @adaptr 当然。但这些过程有机会优雅地结束。如果他们不这样做,除了杀死他们之外别无他法。 (3认同)