WMI Equivalent in UNIX and Linux

I like the whole WMI concept, and I could really make use of it under Linux ( in some scripts ). Is there something like that for Linux systems?

Not really. Are you using WMI to get system parameters, or to query processes, or to change configuration, or monitor for system events, or what?The kernel exposes a lot of information and tunable knobs via the /proc and /sys filesystems. No query language, just a organized hierarchy of directories and files. Some of these files are read-only, read-write, or write-only; some of them are pollable. 

Some services may have custom clients to query and update configuration on the fly — chrony’s chronyc comes to mind, but even the very most basic init has initctl. Newer services like HAL can be introspected and manipulated over D-Bus.

What Is /proc?

WIKIPEDIA: The proc file system acts as an interface to internal data structures in the kernel. It can be used to obtain information about the system and to change certain kernel parameters at runtime (sysctl).

Before we begin to talk about the proc filesystem as a programming facility, we need need to establish what it actually is. The proc filesystem is a pseudo-filesystem rooted at /proc that contains user-accessible objects that pertain to the runtime state of the  kernel and, by extension, the executing processes that run on top of it.

“Pseudo” is used because the proc filesystem exists only as a reflection of the in-memory kernel data structures it displays. This is why most files and directories within /proc are 0 bytes in size.

Broadly speaking, a directory listing of /proc reveals two main file groups. Each numerically named directory within /proc corresponds to the process ID (PID) of a process currently executing on the system. The following line of ls output illustrates this:

ls -ls /proc      
0 dr-xr-xr-x    3 root root           0 Apr 26 23:24 19636
0 dr-xr-xr-x  4 root    root             0 Feb 13 18:33 tty
0 -r--r--r--  1 root    root             0 Feb 13 18:33 uptime
0 -r--r--r--  1 root    root             0 Feb 13 18:33 version
0 -r--------  1 root    root             0 Feb 13 18:33 vmcore

Directory 19636 corresponds to PID 19636, a current bash shell session. These per-process directories contain both subdirectories and regular files that further elaborate on the runtime attributes of a given process. The proc(5) manual page discusses these process attributes at length.

The second file group within /proc is the non-numerically named directories and regular files that describe some aspect of kernel operation. As an example, the file /proc/version contains revision information relevant to the running kernel image.

Proc files are either read-only or read-write. The /proc/version file above is an example of a read-only file. Its contents are viewable by way of cat(1), and they remain static while the system is powered up and accessible to users. Read-write files, however, allow for both the display and modification of the runtime state of the kernel. /proc/sys/net/ipv4/ip_forwarding is one such file. Using cat(1) on this file reveals if the system is forwarding IP datagrams between network interfaces–the file contains a 1–or not–the file contains a 0. In echo(1)ing 1 or 0 to this file, that is, writing to the file, we can enable or disable the kernels ability to forward packets without having to build and boot a new kernel image. This works for many other proc files with read-write permissions.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s