Hi guys, I have a question, on a linux system, with crystal , how can I send the reboot signal to the linux kernel to perform a reboot ?
Basically I have the project to write an init system. I would like to understand how a reboot work.
Is it basically first the init system close all process properly and then write some value in /proc to ask for a reboot?
I am asking for reboot, but as well for other request , like a system shutdown
Is it with this ?
If yes, can I have an example please?
I find how to do guys.
I will leave an example to help you all if you need to use
So according to this page: reboot(2) - Linux manual page
module Init
Syscall.def_syscall reboot, Int64, magic : Int64, magic2 : Int64, op : Int64
end
Init.reboot(magic: 0xfee1dead,
magic2: 0x28121969,
op: 0x1234567)
It is quite simple with crystal ! Thanks to the developers !
3 Likes
zw963
September 28, 2025, 2:47pm
4
I test this code on my laptop, it works (need run with root), but it’s not work when –cross-compile aarm64 use alpine then run it in the raspberry PI, (of cause it maybe a issue of PI)
Just one suggestion zw963, you will be better to test this code under a virtual machine.
Because syscall perform a reboot without performing a proper init shutdown (it don’t interact with the init). It’s not 100% safe basically.
For aarm64, I don’t know sorry :x