About | ACP | Buy | Forum | Industry Watch | Learning Curve | Search | Twitter | Xnews
Home » Learning Curve

Cool Clever Stuff with CLIX III

A look at sysctl.


Buy It

Try It

A Unix user need never complain about a lack of statistics. With sysctl you have statistics coming out of your ears - and some of it might even be useful too.

And the CLIX starter command database has a lot of suggestions how you might use it.

sysctl hw.activecpushow number of active CPUs
sysctl hw.byteordershow machine byte order
sysctl hw.l2cachesizeshow size of L2 cache
sysctl hw.machineshow machine designation
sysctl hw.memsizeshow amount of installed RAM
sysctl hw.modelshow model designation
sysctl hw.ncpushow number of CPUs
sysctl hw.optional.altivecshow presence of Altivec
sysctl hw.optional.floatingpointshow presence of floating point unit
sysctl hw.pagesizeshow system page size
sysctl hw.usermemshow amount of RAM available to user
sysctl kern.boottimeshow boot time
sysctl kern.clockrateshow clock rate
sysctl kern.ipc.maxsockbufshow maximum socket buffer size
sysctl kern.ipc.maxsocketsfshow maximum number of sockets
sysctl kern.maxfilesshow maximum file handles
sysctl kern.maxprocshow maximum processes
sysctl kern.maxvnodesshow max vnodes
sysctl kern.ngroupsshow number of supplemental GIDs
sysctl kern.osreleaseshow OS release
sysctl kern.osrevisionshow OS revision
sysctl kern.ostypeshow OS type
sysctl kern.posix1versionshow POSIX 1 version
sysctl kern.posix2versionshow POSIX 2 version
sysctl kern.securelevelshow secure level
sysctl kern.versionshow kernel version
sysctl net.inet.ip.forwardingshow IP forwarding flag
sysctl net.inet.ip.maxfragpacketsshow max frag packets
sysctl net.inet.ip.ttlshow default TTL
sysctl net.inet.raw.maxdgramshow max raw socket datagram
sysctl net.inet.tcp.path_mtu_discoveryshow path MTU discovery flag
sysctl vm.loadavgshow load averages

Connect the Dots

What's obvious from the above table is that sysctl accesses a database where categories and subcategories are separated by dots. The categories hw, kern, net, and vm are self-explanatory. (And if they're not, they're 'hardware', 'kernel', 'network', and 'virtual memory' respectively.)

This type of system is often referred to as a 'MIB' - a 'management information base'. You can use the '-a' switch to list all the current integer and string values in your system; other data in table form will be available only to specially written programs; exactly what values are available will vary from system to system.

Some of these values are even modifiable, but it's perfectly possible to shoot oneself in the foot too, so it's best not to tread into those waters.

At least it's safe to make mistakes if you're only enquiring.

% sysctl beer.price
top level name beer in beer.price is invalid
%

One at a Time

You might find the output of sysctl -a intimidating; then again you might not; but the safest way is to begin with one category at a time to see what's out there.

% sysctl hw
hw.ncpu: 1
hw.byteorder: 4321
.
.
%

And so forth. Try using the command line sysctl -a | sort to see everything grouped together and in alphabetical order. Try at least the four categories mentioned above. You might not be able to figure out what each and every value means, but you will be able to guess your way to quite a few. Give it a whirl.

About | ACP | Buy | Forum | Industry Watch | Learning Curve | Search | Twitter | Xnews
Copyright © Rixstep. All rights reserved.