How to get system uptime on Linux using C++?

959 views Asked by At

I know there are two ways

  1. sysinfo function call
  2. /proc/uptime

I think sysinfo gets the uptime from the /proc/uptime. But the problem is if the user logouts and logs back in , the timer doesn't get reset. It keeps getting continued.

In windows, GetTickCount64() resets the timer on user logoff and logon. I want something similar in linux.

So how do i find the system elapsed time , since the last logon?

Thank You

edit: c++ code or api function call would be nicer, instead of spawning a process to call who or last command

0

There are 0 answers