Created
January 5, 2026 18:51
-
-
Save alperreha/af9069dbd9cc742f799795e0b15ce180 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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