I know that you can use the time.Sleep(d Duration) function to let the Go program wait for a certain duration. Now I have the use-case that I want to keep the point in time even when the whole OS goes to sleep.
So as an example: When I sleep the go program at 1pm for two hours. And I turn off my computer on 2pm for half an hour until 2:30pm. I still want the code to resume at 3pm and not at 3:30pm.
(Of course when I sleep my OS longer than 3pm the code should resume immediately).
How should I do that with go? Is there a nice function or library for that or should I use cron as a workaround?
Related
I forgot to run a script using time so I don't know how much did it take. The script never completed, I stopped with ctrl+c after a while.
It is the last program I run in the terminal, and since then I entered no commands.
I was wondering if bash automatically stored the execution time of the last program run.
I don't need the time for benchmark purposes, so I don't need a great precision. Does bash (or linux somewhere) store information like "you started this script at this time and stopped it at this other time"?
I tried looking on SO but only find questions on how to time a program, not on how to get the "rough" time it took after you run it without using time.
I am trying to make an Applescript time how long I've used the computer in one day. The timer keeps running while the computer is asleep. I want it to stop on sleep and restart on wake. This is what I've got:
set input to text returned of (display dialog "How many minutes will you use today?"
default answer "")
delay (input * 60)
beep
display dialog "Maximum time for today"
There is a utility named sleepwatcher that you can install, that you can make execute at least shell scripts, with osascripts inside, that could help you keep track of the actual time spent.
How would I create a simple shell script that doesn't do anything, just runs forever, without overloading the CPU. I am using an appify script to make it into an app, so that I can have an app that just runs forever. The reason I do this is so that I can always have an app running and therefore quit out of finder without it opening back up again.
Note: to allow quitting out of finder, run the command defaults write com.apple.finder QuitMenuItem -bool yes in terminal.
Ideally, you could create a job that would sleep forever and just wait on it:
sleep forever &
wait
but in reality you have to pick a finite amount of time to sleep.
while :; do
sleep 65535 &
wait
done
This will only use minimal CPU every 18 hours or so to restart the sleep process. There is probably an upper limit to the size of the argument you can give to sleep, but I don't know what that is (and it is probably implementation-dependent). You can experiment; a larger number will reduce total CPU usage over the life of the program, but even calling sleep once an hour (every 3600 seconds) will use very little CPU.
I have a vb6 program installed on thousands of machines, some XP and some Win7. A Win7 user has called to say that the time the program applies to its events is one hour earlier than the time on the laptop clock, which is correct. It is set to the correct time zone (Eastern) and to daylight savings time adjustment, which is the way my own Win7 machine is set up (and my own machine does not have this problem).
The line of code that obtains this time in VB6 is:
.IssueDate = Now
to put the current time and date into a member variable.
Does anyone have any ideas why a particular machine would be off by one hour, given that the clock is displaying the correct time and the time zone and DST adjustment appear correct?
I'm going to mark this one 'answered' and move on. I asked my user, diffidently, to reboot, not really expecting it to do anything; he did and said the test case he ran did not show the error. I asked him to call me the next time he used the system for its full-blown purpose, but he hasn't done so. My current suspicion is that the PC clock was off by an hour for a period this morning and he didn't notice it, he only noticed the time on the documents the application was producing.
To clarify, I mean time spent while the system is suspended/hibernated, not the calling thread (GetTickCount() returns the number of milliseconds since system boot).
As far as I know, GetTickCount is unrelated to threads and counts the time since the system has started. But it is better to use GetTickCount64 to avoid the 49.7 day roleover.
By the way, to get what you want you need the GetThreadTimes function. It records the creation and exit time and the amount of time the thread has spend in user or kernel space. So you have a nice way to calculate the amount of time spend.
Ok, I missed the "system" part of the question. But that is simple. When in hibernation GetTickCount continues the counting. Because people have suffered from the 49.7 days bug when the computer was in hibernate most of the time. See link text here for more information.
Short answer : Yes.
Longer answer: Read the GetTickCount() docs: It's the elapsed time since system startup, and even MS wouldn't suggest that time stands still while your computer is hibernating...
Yes, GetTickCount does include suspend/hibernate time.
In the following python script I call the Sleep API to wait 40 seconds to give me a chance to put the computer into hibernate mode, and I print the time before and after, and the tick count difference after.
import win32api
import time
print time.strftime("%H:%M:%S", time.localtime())
before = win32api.GetTickCount()
print "sleep"
win32api.Sleep(40000)
print time.strftime("%H:%M:%S", time.localtime())
print str(win32api.GetTickCount()-before)
Output:
17:44:08
sleep
17:51:30
442297
If GetTickCount did not include the time during hibernate it would be much less than the time I hibernated for, but it matches the actual time elapsed (7 minutes 22 seconds equals 442 seconds, i.e. 442000 millisecond "ticks").
For any one looking for answer under Windows CE platform, from docs:
http://msdn.microsoft.com/en-us/library/ms885645.aspx
you can read:
For Release configurations, this function returns the number of
milliseconds since the device booted, excluding any time that the
system was suspended. GetTickCount starts at 0 on boot and then counts
up from there.
GetTickCount() gives you the time in milliseconds since the computer booted. it has nothing to do with the process calling it.
No, GetTickCount() does not include the time the system spend during hibernate.
A simple test proves this.
in Python:
import win32api
win32api.GetTickCount()
-- do hibernate --
win32api.GetTickCount()
and you'll see the result...