Skip to content

Instantly share code, notes, and snippets.

@alperreha
Created January 5, 2026 18:51
Show Gist options
  • Select an option

  • Save alperreha/af9069dbd9cc742f799795e0b15ce180 to your computer and use it in GitHub Desktop.

Select an option

Save alperreha/af9069dbd9cc742f799795e0b15ce180 to your computer and use it in GitHub Desktop.
#define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <sys/reboot.h>
#include <linux/reboot.h>
#include <sys/syscall.h>
int main() {
const char *msg =
"Hey! I already woke up and I am saying hello to you... and I am shutting down now.\n";
write(1, msg, 94);
// Sync + poweroff (best effort)
sync();
// Try reboot syscall directly (works even without /sbin/poweroff)
syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2,
LINUX_REBOOT_CMD_POWER_OFF, 0);
// If poweroff didn't work for some reason, exit anyway.
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment