Best way to shut down programmatically - poweroff?

Using the cli, # poweroff does exactly what I want: a total power-down.
I have seen other posts that describe using system(“poweroff”) in app-code.
But my Wp7601 with Legato 18.08 doesn’t seem to include it.

I entered these lines into my app:
system(“pwd”);
system(“ls”);
system(“poweroff”);
The first two linux system calls result in a reasonable output as shown below, but the “poweroff” call is not found.

Has it been replaced?

Feb 27 05:54:49 swi-mdm9x28 user.info Legato: INFO | maxTrack[1485] | /legato/systems/current/appsWriteable/maxTracker
Feb 27 05:54:49 swi-mdm9x28 user.info Legato: INFO | maxTrack[1485] | bin dev etc lib sys usr

Feb 27 05:54:49 swi-mdm9x28 user.err Legato: =ERR= | maxTrack[1485] | sh:
Feb 27 05:54:49 swi-mdm9x28 user.err Legato: =ERR= | maxTrack[1485] | poweroff: not found
Feb 27 05:54:49 swi-mdm9x28 user.err Legato: =ERR= | maxTrack[1485] |

Ok, that was an easy one.
system("/sbin/poweroff -f");
is a line that works for me.

1 Like

Can I ask why you’re trying to programmatically power off? There won’t be any way to power back on again without physically interacting with the unit right? Is that ok?

Hello @dfrey, I just saw your reply. Sorry to be late but to finish the story for others:
We have a battery powered product that is also a consumer product. Consumers being capable of anything, they will surely run the thing until it dies before thinking to plug it in for re-charge of the battery. My goal was to get a clean, graceful shutdown, which will remain off until the user plugs in to charge. So I monitor the V and when it drops below 3.4 I shutdown. There is hysteresis built into the hardware to delay starting up again until V is back up to 3.7.