photomankc
Posts: 80
Joined: Fri Aug 24, 2012 12:58 pm

Anyway to know if poweroff has been called?

Thu Sep 13, 2018 7:03 pm

Hey all,

I'm working on software to work with my own external pushbutton power switch. I have the basic code running and working. It processes a button press signal from the external microcontroller, and sends a signal to power off to that MCU when I'm ready to shutdown. The MCU gives me 18 seconds after that pulse to complete the OS shutdown and then turns off the MOSFET. I can also send SIGUSR1 to the process and initiate a shutdown via software request as well.

This all works pretty well. What I'd like to be able to do is get this to happen automatically when the OS is going down with the 'poweroff' command. I don't know if there are any places to determine this either from within the C++ program or within scripts for systemd / rc or whatever.

If there is something that I can hook up to run at poweroff then it's a simple matter of calling "killall -s SIGUSR1 powerswitch" and i'll be able to get the power to turn off automagically when you type the command. It would need to happen before the OS starts killing off processes as it will take up to 100ms to notice that a powerkill request is made.

Anyone know of a way to determine that the OS is going down for poweroff instead of just rebooting?

User avatar
DerKleinePunk
Posts: 73
Joined: Thu Feb 23, 2017 9:18 am
Location: Germany
Contact: Website

Re: Anyway to know if poweroff has been called?

Tue Sep 18, 2018 3:26 am

PI 2 und PI 3 1GB Raspbian Strech
Der Wandel von Atom zum Bit ist unwiderruflich und nicht mehr aufzuhalten.
Nicholas Negroponte

photomankc
Posts: 80
Joined: Fri Aug 24, 2012 12:58 pm

Re: Anyway to know if poweroff has been called?

Thu Sep 20, 2018 2:54 pm

That looks promising actually. Thanks! :D

Return to “C/C++”