从用户空间重新启动 Linux 盒子
我需要从用户空间进程重新启动 Linux 机器。 我希望有以下行为:
- 同步文件系统
- 不尝试正常停止进程,转到运行级别 5/6 等,因为我认为事情很糟糕并且会失败
这些要求可以一起实现吗?
我打算在 proc/sysrq-trigger 中写入一个“b”。 有没有更好的办法? (不,那不会让我同步。)
谢谢!
I need to reboot a Linux box from a user space process. I want to have the following behavior:
- sync file systems
- not attempt to gracefully stop processes, go to runlevel 5/6, etc., for I assume things are bad and that would fail
Can those requirements be achieved together at all?
I was planning to write a 'b' into proc/sysrq-trigger. Is there a better way? (No, that won't give me sync.)
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我假设你有root权限。
希望有所帮助。
I'm assuming you have root.
Hope that helps.
好吧,执行sync(1),kill -1,再次同步,kill -9 -1,sync,poweroff -f。
我想这应该可以解决问题!
Well, do sync(1), kill -1, sync again, kill -9 -1, sync, poweroff -f.
That should do the trick, I guess!
这直接来自 sys/reboot.h :
我相信 RB_HALT_SYSTEM 将处理所有sync()等。我通常自己这样做,最后用 RB_AUTOBOOT 触发重新启动。
This directly from sys/reboot.h :
I believe RB_HALT_SYSTEM will handle all sync()s , etc. I usually do that myself, and finally trigger the reboot with RB_AUTOBOOT.
在普通发行版上,最简单的方法是:
这将同步所有文件系统,然后立即重新启动。 请注意,sysrq b 不会同步。
On an ordinary distro, the simplest way to do this is:
This will sync all filesystems, then reboot immediately. Note that sysrq b will NOT sync.