1

I would like to get system uptime in solaris. On linux I would do it like this:

#include <sys/sysinfo.h>

long long get_host_uptime()
{
    struct sysinfo memInfo;
    sysinfo( &memInfo );
    return memInfo.uptime;
}

I would like to find some analog of sysinfo for solaris as well.

Grigor Gevorgyan
  • 6,753
  • 4
  • 35
  • 64
  • 1
    have a look at some of the answers here : http://stackoverflow.com/questions/1661006/getting-the-uptime-of-a-sunos-unix-box-in-seconds-only – Sander De Dycker Apr 04 '17 at 14:32
  • @SanderDeDycker Do you know if the `getutxent()` answer to the question you linked works in a zone? I'd think not, but I don't have access to a Solaris box right now to test. – Andrew Henle Apr 05 '17 at 10:30
  • @SanderDeDycker thanks but those answers miss the "using C++" part :) – Grigor Gevorgyan Apr 05 '17 at 14:08
  • 1
    @GrigorGevorgyan : that's why I didn't mark it as a duplicate. That said, the other question shows several approaches - some of which can easily be used from C++ (including the current top answer with C code, and the several answers with the kstat approach which can be done using libkstat from C++ eg.). – Sander De Dycker Apr 05 '17 at 14:19

0 Answers0