如何从C ++程序中重新启动Linux? [英] How to restart Linux from inside a C++ program?
问题描述
我有一个Qt 4 GUI,我需要在下拉菜单中有一个选项,允许用户选择重新启动计算机。我意识到这可能似乎与重新启动计算机的能力以其他方式,但选择需要留在那里。我尝试使用system()来调用以下内容:
I have a Qt 4 GUI where I need to have a option in a drop-down menu that allows the user to choose to restart the computer. I realize this might seem redunant with the ability to restart the computer in other ways, but the choice needs to stay there. I've tried using system() to call the following:
- 一个suid-root shell脚本
- 非suid shell脚本
- 一个suid-root二进制程序
的他们只是导致
reboot: must be superuser
才能打印。使用system()调用reboot直接做同样的事情。我不是特别附加到使用system()来做到这一点,但它似乎是最直接的选择。
to be printed. Using system() to call reboot directly does the same thing. I'm not especially attached to using system() to do this, but it seemed like the most direct choice.
如何从GUI重新启动系统? / p>
How can I reboot the system from the GUI?
推荐答案
在Linux中:
#define LINUX_REBOOT_CMD_POWER_OFF 0x4321fedc
sync();
reboot(LINUX_REBOOT_CMD_POWER_OFF);
这篇关于如何从C ++程序中重新启动Linux?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!