Graceful shutdown

Colibri iMX6 512 MB IT

Hi everyone,
does anyone know the best, fastest and relatively safe method of shutting down my iMX6?

I know that at the dos prompt, i can type for example:

sudo shutdown now

but there are two problems:

  1. In my application, there is no screen or terminal to type on. I would like to use a GPIO to run the command from C.
    When i try this, I get messages like

sudo: shutdown: command not found

I also tried to use sudo systemctl but I see now that systemd is not installed…

The internet is full of ideas, such as this thread on superuser.:

but I guess what i am after is something that will shut down relatively safely in under 5 seconds, if possible.

the 2nd part of my problem, is that I believe my programs themselves are part of the problem. They do not respons to SIGINT, SIGTERM, SIGKILL etc. i am a bit of a linux N00b, so if anyone has some sample code they would like to share…

I think I want my program to receive the GPIO, give the command to shutdown which will hopefully shut down my other python programs and then close up some files and call exit(0);


sprintf(systemCommand, "echo password | sudo shutdown -r now");  // shut down the system
printf("Attempting to shut down...\n");

  1. How to respond to SIGTERM in python?

PS the reason it needs to be fast, is that if power is lost to our system I have proposed that we read a digital input of the supply voltage (at an earlier stage) and then some sort of supercapacitor near the Colibri to allow the system to shut down “as gracefully as possible”. I may need about a 2F capacitor for this. Is there anyone else who has this issue?

Seems to take about 10 seconds with nothing running on it at the moment.

Anything is helpful, thanks!

Have you tried “reboot -f -d 0” ?

Some source code related to shutdown:

Do you know if this will give me time to exit my programs gracefully? Or is this just how I command a shutdown from C?

Do you know if this will give me time to exit my programs gracefully?

I don’t know if anyone but you can properly answer what passes as enough time for your system to exit “gracefully”.

Linux also provides an GPIO power-off driver: GPIO (Linux) | Toradex Developer Center

There’s additional ways to manipulate the power state of the system from within a container via dbus as well: Torizon Best Practices Guide | Toradex Developer Center

Though in the end you’d need to do the proper testing yourself whether these allow a graceful shutoff as you desire.

Best Regards,