Getting swap info without kvm access
Dan Nelson
dnelson at allantgroup.com
Fri Jul 2 19:28:41 PDT 2004
In the last episode (Jul 02), gomalley at mthoodcards.com said:
> I've written an Afterstep applet that retrieves and displays
> different time and system information. The Linux port uses a few
> functions like gmtime() and gethostname() and reads most of the info
> from /proc files. The FreeBSD port used the function calls and gets
> most of the info from sysctl() calls, except for the swap space. As
> written now, that info is retrieved with kvm_getswapinfo(). The
> problem is that that function requires access to /dev/mem which isn't
> available without sgid privileges. The current work-around is to
> display 0 for swap space if the applet is running un-privileged.
>
> I've searched and browsed the mailing lists, I've poured over the
> .h's, .c's, sysctl -a and man pages for weeks but I'm stumped. Is
> there some way to get total and either free or used swap space
> without using /dev/mem? If not, why is that one piece of info not
> available through a sysctl() call?
It is in 5.x. The kvm_getswapinfo() function reads the vm.swap_info
sysctl when getting status on a live system. You'll just have to
install the applet setgid kmem to get swap info on 4.x.
--
Dan Nelson
dnelson at allantgroup.com
More information about the freebsd-questions
mailing list