

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
8 messages in net.java.dev.jna.users[jna-users] call to sysinfo() causes ...| From | Sent On | Attachments |
|---|---|---|
| Joel Uckelman | Apr 7, 2009 8:37 am | |
| Timothy Wall | Apr 7, 2009 8:47 am | |
| Joel Uckelman | Apr 7, 2009 9:05 am | |
| Kevin Burton | Apr 7, 2009 9:56 am | |
| Timothy Wall | Apr 7, 2009 9:58 am | |
| Joel Uckelman | Apr 7, 2009 12:19 pm | |
| Joel Uckelman | Apr 7, 2009 12:22 pm | |
| Kevin Burton | Apr 7, 2009 1:33 pm |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | [jna-users] call to sysinfo() causes crash | Actions... |
|---|---|---|
| From: | Joel Uckelman (ucke...@nomic.net) | |
| Date: | Apr 7, 2009 8:37:54 am | |
| List: | net.java.dev.jna.users | |
Hi,
I'm trying to call the sysinfo() function from the Linux C library:
int sysinfo(struct sysinfo *info);
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 */ };
Here's my test case:
import com.sun.jna.Library; import com.sun.jna.Native; import com.sun.jna.NativeLong; import com.sun.jna.Structure;
public class Sysinfo {
public static interface Libc extends Library { public static final 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; public String _f; }
int sysinfo(sysinfo info);
String strerror(int errno);
public static final Libc INSTANCE = (Libc) Native.loadLibrary("c", Libc.class); }
public static void main(String[] args) throws Exception {
long ram_mbytes = -1L;
final Libc.sysinfo info = new Libc.sysinfo(); if (Libc.INSTANCE.sysinfo(info) == 0) { info.read(); ram_mbytes = (info.totalram.longValue() * info.mem_unit) >> 20; } else { final int errno = Native.getLastError(); System.err.println( "Error " + errno + ": " + Libc.INSTANCE.strerror(errno)); }
System.out.println(ram_mbytes + " MB"); } }
About a third of the time when I run this, the JVM crashes at the call to Libc.INSTANCE.sysinfo(). The other two-thirds of the time, I get the correct output. Does anyone see what I'm doing wrong here?
-- J.







