The computer (running Ubuntu 14.04) is connected to a networked device which controls the power supply to the computer itself.

On receiving a certain signal A, the computer must send a signal B to this networked device which (among other stuff) will cut power to the computer.


When should I send this signal B to the networked device so as to minimize the damage done from the power cut?

I assume I can trigger the shutdown sequence with signal A and somewhere along the shutdown sequence, send signal B. But when should I actually send it?

I assume my /etc/rc0.d would look something like below

K98signalB # Actually sends signalB to cut power
K99networking # Renamed from K01networking, since I need to keep networking alive

closed as too broad by mdpc, user34720, Michael Homer, slm Apr 4 at 3:17

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    You could have a look at how nut (opensource UPS monitoring framework) does it. – Stéphane Chazelas Apr 1 at 13:14
  • Cutting power should be delayed, then you can just shutdown normally. Otherwise it may be a use case for shutdown ramfs (like initramfs in reverse). – frostschutz Apr 1 at 13:45

Assuming linux

I looked into something similar to this some years ago. The question I cannot answer is whether networking will still be available at the right time.

To actually pull the plug on the power, instead of trying to hook into SystemD or sysvinit, you really should try to hook into the kernel directly with a kernel mod.

When I searched on this topic I eventually came up with some information here: How does the system shutdown of a linux kernel work internally?

This led me to kernel code here: https://elixir.bootlin.com/linux/v5.0.5/source/arch/arm64/kernel/process.c#L136

void machine_power_off(void)
    if (pm_power_off)

To do this properly you would write a kernel module containing a function talk to the power switch over the network, and then register your function in the function pointer pm_power_off.

Triggering a system shutdown might be even more system dependent. It might be that the simplest way would be to invoke an existing command line program such as sutdown or poweroff.

Not the answer you're looking for? Browse other questions tagged or ask your own question.