Restart Mac OS X ungracefully using a C++ call?

爱⌒轻易说出口 提交于 2019-12-01 13:16:30

问题


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

回答1:


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>.

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.




回答2:


JMP 0xFFFF0

:-)



来源:https://stackoverflow.com/questions/3386983/restart-mac-os-x-ungracefully-using-a-c-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!