The light-weight ClusterIt toolkit mostly worked on linux, but dtop (distributed top) still expected BSD-style top syntax.
Here’s a diff I wrote to make dtop work on recent versions of Linux (tested on CentOS 5.5 x86_64):
$ diff dtop.org.c dtop.c
311a312,322
> char buf2[30];
>
> if (strstr(c, "Swap:") != NULL) {
> sscanf(c, "Swap: %30s total, %*s used, %30s free", buf, buf2);
> nd->swap = dehumanize_number(buf);
> nd->swapfree = dehumanize_number(buf2);
> nd->inactmem = nd->wiredmem = nd->execmem = 0;
> return;
> }
>
>
344a356
> #if ! defined(__linux__)
364a377
> #endif
470a484,486
> #if defined(__linux__)
> case 11:
> #else
471a488
> #endif
517a535,539
> #if defined(__linux__)
> } else if (strstr(c, "Tasks:") != NULL) {
> sscanf(c, "Tasks: %d ",&nodedata[nn].procs);
> #else
519a542
> #endif
The output of dtop on linux looks like this:
HOSTNAME PROCS LOAD1 LOAD5 LOAD15 ACTIVE INACT FILE FREE SWPFRE SWUSED g00-int 64 0.11 0.04 0.01 0 0 0 7345M 2047M 0.00% g01-int 64 0.00 0.01 0.00 0 0 0 7033M 2047M 0.00% g02-int 61 0.08 0.02 0.01 0 0 0 6980M 2047M 0.00% g03-int 64 0.16 0.06 0.01 0 0 0 7011M 2047M 0.00% g04-int 64 0.04 0.04 0.01 0 0 0 6996M 2047M 0.00% g05-int 61 0.02 0.01 0.00 0 0 0 7424M 2047M 0.00%
Here is the final, hardened version of dtop.c that uses secure C programming techniques (strn API and double-free safe.)
My long-term preference would be to rewrite dtop in Perl since parsing text input in old-school C is brittle.
Also, dtop should be able to handle top results from heterogeneous systems, and the linux ifdefs contribute to preventing that.
And here are some of the debugging commands I used:
ulimit -S -c unlimited > /dev/null 2>&1 valgrind -v --leak-check=full --show-reachable=yes --track-origins=yes ./dtop gdb ./dtop core
Dan Saks: Why size_t matters
Karpov: About size_t and ptrdiff_t


