Ejemplo n.º 1
0
 /** {@inheritDoc} */
 @Override
 public long getSystemUptime() {
   IntByReference size = new IntByReference();
   if (0 != SystemB.INSTANCE.sysctlbyname("kern.boottime", null, size, null, 0)) {
     LOG.error("Failed to get Boot Time. Error code: " + Native.getLastError());
     return 0L;
   }
   // This should point to a 16-byte structure. If not, this code is valid
   if (size.getValue() != 16)
     throw new UnsupportedOperationException("sysctl kern.boottime should be 16 bytes but isn't.");
   Pointer p = new Memory(size.getValue() + 1);
   if (0 != SystemB.INSTANCE.sysctlbyname("kern.boottime", p, size, null, 0)) {
     LOG.error("Failed to get Boot Time. Error code: " + Native.getLastError());
     return 0L;
   }
   // p now points to a 16-bit timeval structure for boot time.
   // First 8 bytes are seconds, second 8 bytes are microseconds (ignore)
   return System.currentTimeMillis() / 1000 - p.getLong(0);
 }
Ejemplo n.º 2
0
 public final long getLong(long offset) {
   checkBounds(offset, 8);
   return ptr.getLong(offset);
 }