Thus spake Kevin Burton:
I just wrote an implementation of this recently... this works:
public class sysinfo {
private static SysinfoInterface delegate
= (SysinfoInterface)Native.loadLibrary( "c",
SysinfoInterface.class);
public static class SysinfoStructure extends Structure {
public long uptime; /* Seconds since boot */
public long[] loads = new long[3]; /* 1, 5, and 15 minute load
averages */
public long totalram; /* Total usable main memory size */
public long freeram; /* Available memory size */
public long sharedram; /* Amount of shared memory */
public long bufferram; /* Memory used by buffers */
public long totalswap; /* Total swap space size */
public long freeswap; /* swap space still available */
public short procs; /* Number of current processes */
public long totalhigh; /* Total high memory size */
public long freehigh; /* Available high memory size */
public int mem_unit; /* Memory unit size in bytes */
//char _f[ 20-2*sizeof(long)-sizeof(int)]; /* Padding for libc5 */
};
public static SysinfoStructure sysinfo() {
SysinfoStructure result = new SysinfoStructure();
delegate.sysinfo( result );
return result;
}
}
interface SysinfoInterface extends Library {
void sysinfo(sysinfo.SysinfoStructure sysinfo);
Have you tested this on both 32- and 64-bit systems? This is exactly what
I had originally, and it caused the JVM to crash on 32-bit systems. Based
on the JNA docs, you should be using NativeLong instead of long.