可以在 Linux 上中止关机吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/526329/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 16:58:05  来源:igfitidea点击:

Possible to abort shutdown on Linux?

linuxunixshutdownhaltprocess-control

提问by David

I'm familiar with and use shutdownin Linux, and typically just do

我熟悉并shutdown在 Linux 中使用,通常只是做

> shutdown -h now

> shutdown -h now

But is there a way to stop shutdown from happening, say if I aim to shutdown 10 minutes from now and then in 5 minutes time I discover I really don't want to shut down?

但是有没有办法阻止关机的发生,比如说,如果我打算在 10 分钟后关机,然后在 5 分钟后我发现我真的不想关机?

采纳答案by skiphoppy

You can use  ps  to find the shutdown process and abort it, for example with ps|grep shutdown.

您可以使用  ps  来查找关闭过程并中止它,例如使用ps|grep shutdown.

Alternate and less eyeball-intensive versions of this:

替代和较少眼球密集的版本:

pkill shutdown
killall shutdown
kill `cat /var/run/shutdown.pid`

回答by chaos

shutdown -c  is "cancel shutdown" on reasonably recent shutdowns.

shutdown -c  在最近的shutdowns上“取消关闭” 。

The syntax also supports shutdown -c <message>for announcement purposes, so that's handy if other people use the machine.

该语法还支持shutdown -c <message>公告目的,因此如果其他人使用该机器,这将很方便。

回答by Chris Bunch

From shutdown's man page on BSD systems:

来自shutdownBSD 系统的手册页:

A scheduled shutdown can be canceled by killing the shutdown process (a SIGTERM should suffice).

可以通过终止关闭进程来取消计划的关闭(SIGTERM 就足够了)。

回答by Joshua

If you're a second late on the draw for shutdown -c, and already root on the console, a very fast # init 5will cancel a shutdown after init changes runlevel.

如果你是一个第二晚抽签shutdown -c,并已根在控制台上,一个非常快的# init 5将初始化运行级别改变之后取消关机。

NOTE: This answer is mostly obsolete now. init 5isn't very useful on systemd, which, sadly, most systems now use.

注意:这个答案现在大部分已经过时了。init 5在 systemd 上不是很有用,遗憾的是,大多数系统现在都在使用它。