How to restart Linux from inside a C++ program?

后端 未结 7 1858
天涯浪人
天涯浪人 2021-02-07 08:59

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 t

7条回答
  •  庸人自扰
    2021-02-07 09:39

    The reboot function is described in the Linux Programmer's Manual. Under glibc, you can pass the RB_AUTOBOOT macro constant to perform the reboot.

    Note that if reboot is not preceded by a call to sync, data may be lost.

    Using glibc in Linux:

    #include 
    #include 
    
    sync();
    reboot(RB_AUTOBOOT);
    

提交回复
热议问题