1

I need a method which can give me the number of miliseconds or seconds, elapsed since the system was started. I could parse /proc/uptime , but i can't afford to lose performance over this I/0 and parsing.

I'm using Linux and C/C++. Maybe i can put some Qt/Boost, but is better to be something native.

Cumatru
  • 695
  • 2
  • 12
  • 34

2 Answers2

13

Why cannot you afford reading /proc/uptime? It is not a real file so reading it should be quick (there is no real i/o involved, since the /proc/ filesystem contains pseudo-files). Did you benchmark its reading?

You might also call clock_gettime with CLOCK_MONOTONIC

NB. This is specific to Linux.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
4

You could try sysinfo.h.

Franz
  • 1,993
  • 13
  • 20