This question already has an answer here:

My RPi3B+ is an embedded front end for a scientific instrument. I have an interface PCB with a 3amp 5v regulator, driven by a 48v supply. I monitor the 48v with ADC polled each 100ms, then sudo shutdown at a critical voltage(`40v). I have several seconds depending on how much capacitance I design into the 48v supply. At any time the user can power down or power failures can happen. My questions are : how long do I have until it's safe for the 5v to turn off? Can I detect in software when it's safe? Can I depower the display to stretch the time the 5v lasts? Graham

marked as duplicate by goldilocks May 4 at 2:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    Welcome. In case the duplicate isn't clear, the only safe time to pull the plug is after the operating system is properly shut down. The Pi is like any other general purpose computer in this sense. The risk is filesystem corruption (which mostly depends upon how active the system is at the time), which you can reduce by using a read-only fs or using the sync option when it is mounted (see man mount, you can stick these options in /etc/fstab as well). – goldilocks May 3 at 15:54
  • 2
    Even though this question is marked as a duplicate, recent Raspbian have an option to assert a GPIO output on poweroff which is designed specifically for the purpose. See raspberrypi.stackexchange.com/a/94399/8697 – Milliways May 4 at 0:21
  • 1
    That's handy. I see I did misinterpret the question here; that one seems to cover it better. WRT to software hooks, I am sure you can do something with systemd, but it would be better to ask about that specifically (and the GPIO is likely a better option anyway). – goldilocks May 4 at 2:43

Browse other questions tagged or ask your own question.