Page 1 of 1

Program that starts when power is on, and stops when off

Posted: Mon Aug 08, 2016 8:27 am
by profeciak
Hi,

I'm a beginner in programming on raspberry pi. I would like to know is there is any easy way to make a python script that will run my main program when the raspberry pi is on. Also I would like to make this program stop with the moment when the power is off. I have to save my measure data to the file after each run of that program. I've been trying with rc.local and it seems like the program is running but when I reboot the device there is no file with the data gathered. Thanks for your help.

Re: Program that starts when power is on, and stops when off

Posted: Mon Aug 08, 2016 10:19 am
by topguy
When the power is turned off everything stops, no data will be written to the flash after that.

Also if a program expect to be shut-off at any moment it should always make sure that any data written to a file is "flushed" to the disk as soon as possible.
Look at functions like fflush() and sync(). ( I dont know what they are in Python )

Re: Program that starts when power is on, and stops when off

Posted: Wed Aug 17, 2016 11:57 am
by profeciak
Thanks fot Your reply it helped. :)