Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The (Linux-specific) system call <code>sysinfo(struct sysinfo* info)</code> fills in <code>info</code> with the following:</p> <pre><code>struct sysinfo { long uptime; /* Seconds since boot */ unsigned long loads[3]; /* 1, 5, and 15 minute load averages */ unsigned long totalram; /* Total usable main memory size */ unsigned long freeram; /* Available memory size */ unsigned long sharedram; /* Amount of shared memory */ unsigned long bufferram; /* Memory used by buffers */ unsigned long totalswap; /* Total swap space size */ unsigned long freeswap; /* swap space still available */ unsigned short procs; /* Number of current processes */ unsigned long totalhigh; /* Total high memory size */ unsigned long freehigh; /* Available high memory size */ unsigned int mem_unit; /* Memory unit size in bytes */ char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding for libc5 */ }; </code></pre> <p>Of which <code>totalswap</code> and <code>freeswap</code> might be what you are after.</p> <p>I don't know how you do native platform invocation in Java, but this is a good alternative to parsing the <code>/proc/swaps</code> file yourself.</p> <h1>EDIT:</h1> <p>I played a bit with <a href="http://www.github.com/twall/jna" rel="nofollow">JNA</a> and came up with this:</p> <pre><code>import com.sun.jna.Library; import com.sun.jna.Native; import com.sun.jna.Structure; import com.sun.jna.NativeLong; public class Test { public interface CStdLib extends Library { static class SysInfo extends Structure { public NativeLong uptime; public NativeLong[] loads = new NativeLong[3]; public NativeLong totalram; public NativeLong freeram; public NativeLong sharedram; public NativeLong bufferram; public NativeLong totalswap; public NativeLong freeswap; public short procs; public NativeLong totalhigh; public NativeLong freehigh; public int mem_unit; /* some padding? */ } int sysinfo(SysInfo info); } public static void main(String[] args) { CStdLib c = (CStdLib)Native.loadLibrary("c", CStdLib.class); CStdLib.SysInfo s = new CStdLib.SysInfo(); c.sysinfo(s); System.out.println("totalram: " + s.totalram); } } </code></pre> <p>Unfortunately you're going to have issues where the value is too large for a signed <code>long</code> and thus you might get the wrong value in Java, which I am seeing when trying to read the swap values on my machine.</p> <p>Hope this helps! (Caveat: I have never been confused with a Java programmer <code>:)</code> )</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload