💾 Archived View for bbs.geminispace.org › s › Linux › 15488 captured on 2024-08-25 at 10:46:58. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2024-08-25)
-=-=-=-=-=-=-
So, I tried to fumble a little with Linux syscalls and tried to implement a program that restarts the computer.
#include <unistd.h> #include <sys/reboot.h> int main() { sync(); if (reboot(LINUX_REBOOT_CMD_RESTART) < 0) write(2, "Failure.\n", 9); return 1; }
After a quick, successful test, I checked how others implement the reboot. To my surprise, busybox tries to send a signal to init instead of using the reboot syscall, like I did. This makes me wonder, why that is.
Mar 05 · 6 months ago · 👍 stack
Does your program let programs to shut down clearly?
🔭 DocEdelgas [OP] · Mar 06 at 00:13:
Not really. Rather, it powers off the system in an instant.
Ah, init systems are responsible for both bringing up and down your system.
For example letting databases to shut down in a known state so that it can continue with all the data intact. While sync() system call might look like it would do that but if it is at all like sync command it only affects filesystems.
this is not kill (1) it is more like murder (8) 😅