Domanda

i am trying to make a program run for 13 hours every 7 days and then the program will stop and the task will end. However i may turn off my computer during that time and then do you know if when i start the task again the timer will resume?

for example

i start my task it runs for 5 hours i then turn off my computer.

next day i turn my computer on and the task starts and runs for 8 hours

then...

will the task end becasue it has reached 13 hours or will it continue to run till it reaches 13 hours?

is there a way to make the timer resume whenever i turn my computer off or do you know of any program that will do this

any help would be appreciated thanks

È stato utile?

Soluzione

To some degree, it depends on the operating system your computer or mobile device runs. If you are running Windows 2000+ or a UNIX derivative (Linux, BSD, OSX), we have use of tools like cron to start us off. If it's a mobile device, we have a bit more work to do.

I'll assume you have a Windows or UNIX device to start. Therefore, you have the Startup/init.d layers of the OS to kick things off when you begin. This is used just to fire things off at power up. We might, for example, write a shell script/WSH script that, at login/startup, runs your up. At this point, you are running, but we want to do a bit more.
Since your app can now be started by the system, we need to make sure it stays running and is restarted if necessary, even if the system is not rebooted. For example, it could be killed/terminated by other events. Our goal is to start your script up at system start, and ensure it runs for 7 hours. Assuming UNIX/Linux:

This can be done with two tasks:

  • One task just ensures that we've run at least every seven days
  • The other task ensures when we run, we run for seven hours and no more.

Our first task is a pair of cron scripts. One runs ever 30 minutes. It's sole task is to check to ensure the main worker task is either running or finished. If it's not finished, and it's not running for some reason, start it. The second cron task runs every seven days and when run, cleans up the markers from the worker task.

Our main worker task, when run, splits its workload into 30 minute segments. It runs each segment, and leaves a "breadcrumb" in temporary storage somewhere -- basically, it says "I've done another 30 minutes of work". When it has 14 crumbs, it's done.

How this all works:

  1. Cron or init.d starts up the main worker thread
  2. THe worker thread runs, hopefully to 14 "chunks of work" and terminates.
  3. Each week, the other cron tasks check to see if we had 14 chunks. If we did, it was a successful run. Remove them and start over. If not, restart the worker task.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top