So, I tried to fumble a little with Linux syscalls and tried to implement a program that restarts the computer.

#include 
#include 

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.

=> Posted in: s/Linux | ๐Ÿ”ญ DocEdelgas

2024-03-05 ยท 11 months ago ยท ๐Ÿ‘ stack

4 Comments โ†“

=> ๐Ÿš‚ MrSVCD ยท 2024-03-05 at 21:01:

Does your program let programs to shut down clearly?

=> ๐Ÿ”ญ DocEdelgas [OP] ยท 2024-03-06 at 00:13:

Not really. Rather, it powers off the system in an instant.

=> ๐Ÿš‚ MrSVCD ยท 2024-03-06 at 08:53:

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.

=> ๐Ÿ“ท sjlxndr ยท 2024-03-08 at 01:29:

this is not kill (1) it is more like murder (8) ๐Ÿ˜…

Proxy Information
Original URL
gemini://bbs.geminispace.org/s/Linux/15488
Status Code
Success (20)
Meta
text/gemini; charset=utf-8
Capsule Response Time
85.842191 milliseconds
Gemini-to-HTML Time
0.526977 milliseconds

This content has been proxied by September (3851b).