Answer the question
In order to leave comments, you need to log in
What is the best way to calculate the running time of a program?
I have a program that in the future should start with the computer and shut down accordingly. How to fix the time at startup is understandable, but how to do this before turning off the computer?
Program in python.
I thought maybe every 5 minutes to fix the time, and then compare the last recorded (which will indicate the shutdown of the computer) and the time of the new start.
Maybe there is a smarter way to do this?
I didn’t google it on the Internet, everyone there talks about measuring the work of a program that processes values and turns off, this is not my case.
Answer the question
In order to leave comments, you need to log in
In linux, you can execute a script upon completion, suspending the OS. For example, askubuntu.com/questions/416299/execute-command-bef...
But if the computer is simply turned off, then the data will be lost. Then the only way out is to periodically fix the time.
Just write to the log the program start time and the program end time.
If the log shows that there are two launches in a row, then something interrupted it. Using the Linux system log or Windows logs, you can see when the computer turned off and calculate the time.
If you need to automate, periodically write the current time to a temporary file and make a simple workaround, depending on how critical it is to catch the time before shutting down.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question