使用C ++调用不正常地重新启动Mac OS X? [英] Restart Mac OS X ungracefully using a C++ call?
问题描述
如何在不调用任何子进程的情况下使用 C ++ (不是Objetive-C )重新启动Mac OS X?不在乎它是否是不优雅的.
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
推荐答案
我不认为您为什么不想创建一个新进程,但是如果您真的不想创建execve("reboot",0,0)
,它将运行reboot
,替换当前进程.您需要包含<unistd.h>
.
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 run reboot
, replacing the current process. You'll need to include <unistd.h>
.
我假设这在Mac OS上可用;它应该在所有POSIX平台上.
I'm assuming this is available on Mac OS; it should be on all POSIX platforms.
更新
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.
这篇关于使用C ++调用不正常地重新启动Mac OS X?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!