man reboot (2)
#include <unistd.h>
#include <sys/reboot.h>
int main () {
sync(); // If reboot() not preceded by a sync(), data will be lost.
setuid(0); // set uid to root, the running uid must already have the
// appropriate permissions to do this.
reboot(RB_AUTOBOOT); // note, this reboots the system, it's not as
return(0); // graceful as asking the init system to reboot.
}
Pre-systemd, вы также можете иногда сойти с рук:
int main() {
sync();
kill(1, SIGTERM);
return 0;
}
Этот метод был более распространенным навстроенные системы, в которых программа запускается под одной оболочкой, но уничтожение initd также было эффективным.Обратите внимание, что в более новых версиях GNU / Linux, использующих systemd / upstart, SIGTERM
игнорируется systemd.