7

Is there any Mac OS X equivalent header file for sysinfo.h in Linux. I am porting code from Linux to Mac but the structure struct sysinfo is not found.

Edit: ==More info== In Linux platform I use a Header file <sys/sysinfo.h> which is not found in Mac. By including the header in Linux I perform following operation: struct sysinfo s; sysinfo(&s);

Which in result give me some system related info. Now as I porting my project from Linux to Mac I want to know is there any similar functionality serve by Mac.

Please help.

Thanks in advance.

pcbabu
  • 2,219
  • 4
  • 22
  • 32
  • You might be better served asking how to achieve your ultimate aim rather than asking for the OS X equivalent of a Linux header file. – mttrb Sep 21 '12 at 03:13
  • I edit my post....could you please see it one more time. Thanks for your help. – pcbabu Sep 21 '12 at 03:31
  • What information are you trying to get? load, uptime, memory usage etc? – mttrb Sep 21 '12 at 03:34
  • [link](http://linux.about.com/library/cmd/blcmdl2_sysinfo.htm) these are the values return by Linux. Can I have these values in Mac or some of these values. Thanks again. – pcbabu Sep 21 '12 at 03:49
  • 1
    I think @duskwuff has told you how to access pretty much all the information returned by `sysinfo` on Linux. – mttrb Sep 21 '12 at 03:57

1 Answers1

15

The closest equivalent to sysinfo in Mac OS X is sysctl / MIB. It doesn't return a sysinfo struct directly, but most of the values in that structure are available as sysctl keys. For instance:

  • uptime is approximated by kern.boottime (although that reflects the actual boot time, not the running time)
  • loads is available as vm.loadavg
  • totalram = hw.memsize (in bytes)
  • freeram, sharedram, and bufferram are complicated, as the XNU memory manager works differently from Linux's. I'm not sure if the closest equivalent values ("active" and "inactive" memory) are exposed.
  • totalswap and freeswap are reflected in vm.swapusage. (But note that OS X allocates swap space dynamically.)
  • procs doesn't appear to have any equivalent.
  • totalhigh and freehigh are specific to i386 Linux.