使用 C++ 不正常地重新启动 Mac OS X称呼?
如何使用 C++(不是 Objetive-C)重新启动 Mac OS X,而不调用任何子进程?不在乎它是否不雅。
system("reboot"); //Is not acceptable as it relies on invoking a process
How do I restart Mac OS X using C++ (not Objetive-C) without invoking any child processes? Don't care if it's ungraceful.
system("reboot"); //Is not acceptable as it relies on invoking a process
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不明白为什么你不想创建一个新进程,但如果你真的不想,那么
execve("reboot",0,0)
将运行重新启动
,替换当前进程。您需要包含
。我假设这在 Mac 操作系统上可用;它应该在所有 POSIX 平台上。
更新
Mac OS 似乎有一个
重新启动
系统调用。reboot(RB_AUTOBOOT);
可能会执行您想要的操作。否则它可能会损坏您的硬盘。尝试像这样针对操作系统进行操作时要非常小心。I can't think why you wouldn't want to create a new process, but if you really don't want to, then
execve("reboot",0,0)
will runreboot
, replacing the current process. You'll need to include<unistd.h>
.I'm assuming this is available on Mac OS; it should be on all POSIX platforms.
UPDATE
It appears that Mac OS has a
reboot
system call.reboot(RB_AUTOBOOT);
might do what you want. Or it might trash your hard drive. Be very careful when trying to work against the operating system like this.JMP 0xFFFF0
:-)
JMP 0xFFFF0
:-)