system uptime?

Just starting out? Need help? Post your questions and find answers here.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

system uptime?

Post by jassing »

There are a bunch of ways to get the system uptime, but the ways I've uncovered, all seem to fail after a period (4 days, 2 weeks, where they just start over again)

I know that there is a finite limit to how high of a resolution can be used with a timer, but what's the best way?

I am writing to an sqlite database, involving mutexes and threads -- so the thread that gets the mutex, might not be "in order" -- so I need to be able to order them in a query so that they can be read in order.

Thanks
-j
(Windows-only, ok)
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: system uptime?

Post by Shield »

GetTickCount64 if your system meets the requirements.
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
Blankname
Enthusiast
Enthusiast
Posts: 120
Joined: Sun Oct 14, 2012 9:11 am

Re: system uptime?

Post by Blankname »

GetTickCount_() wrote:The elapsed time is stored as a DWORD value. Therefore, the time will wrap around to zero if the system is run continuously for 49.7 days. To avoid this problem, use the GetTickCount64 function. Otherwise, check for an overflow condition when comparing times.
If you need a higher resolution timer, use a multimedia timer or a high-resolution timer.
Directly from MSDN.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: system uptime?

Post by jassing »

yup; knew that; but thanks.
136
New User
New User
Posts: 2
Joined: Fri Jun 07, 2013 11:02 am

Re: system uptime?

Post by 136 »

User avatar
em_uk
Enthusiast
Enthusiast
Posts: 366
Joined: Sun Aug 08, 2010 3:32 pm
Location: Manchester UK

Re: system uptime?

Post by em_uk »

I posted this over there, so may as well post here as a more recent thread.

Code: Select all

Procedure.s UpTime() ; For XP or higher. Pretty much instant now :) ~ em_uk
  p=RunProgram("cmd.exe","/c net statistics workstation ","",#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read)
  If p
    While ProgramRunning(p) : o$+ReadProgramString(p)+#CRLF$ : Wend : CloseProgram(p)
    up$=Trim(Mid(o$,FindString(o$,"Statistics since",1)+16)) : up$=Left(up$,FindString(up$,#CRLF$,1)-1)
  EndIf
  ProcedureReturn up$
EndProcedure

Debug UpTime()
----

R Tape loading error, 0:1
Post Reply