#include <stdlib.h>
#include <stdio.h>
#include <linux/reboot.h> /* Definition of LINUX_REBOOT_* constants */
#include <unistd.h>
#include <sys/syscall.h> /* Definition of SYS_* constants */
int reboot(int cmd);
/**
* https://man7.org/linux/man-pages/man2/reboot.2.html
*/
int main() {
// int r = syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2,
// LINUX_REBOOT_CMD_RESTART, NULL);
int r = reboot(LINUX_REBOOT_CMD_RESTART);
if (r == -1) {
perror("reboot");
exit(EXIT_FAILURE);
}
return EXIT_SUCCESS;
}
注意;运行的时候要加sudo。