Toad (toad at amphibian.dyndns.org) wrote:
> > * Headers may be one or two lines, and may or may not be repeated
> > intermittently during the normal running.
>
> Headers should also uniquely identify the format, right?
They may change with minor versions of each OS or package. Rather
than have a separate parser for each "format", I think it would
make more sense to use the headers themselves to determine which
fields you should read in the data. In pseudocode:
{
read a line into line1
read a line into line2
if (line2 is NOT all whitespace and numbers) {
line1 := line2
}
parse line1 into fields by whitespace
N := number of fields
scan the fields and save the index (I) of the one we want
/* we are discarding line2, which is the first all-numeric line */
while (true) {
read a line into line1
if (line1 is NOT all whitespace and numbers) {
/* discard this line, do nothing */
}
parse line1 into fields by whitespace
if (number of fields != N) {
/* discard this line, do nothing */
} else {
do whatever we're supposed to do with field I
}
}
}
Also make sure the locale is set to "C" before invoking vmstat. (I
forgot to do that in my previous message, but en_US.* is usually
the same as C.)
The major assumption in the algorithm above is that the final line
of headers matches the numeric data fields. This is true in all
of the vmstat implementations to which I have access.
--
Greg Wooledge | "Truth belongs to everybody."
greg at wooledge.org | - The Red Hot Chili Peppers
http://wooledge.org/~greg/ |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
URL:
<https://emu.freenetproject.org/pipermail/devl/attachments/20030517/3ec4e199/attachment.pgp>