top: proc summary mismatch

Dmitry Lohansky sq at sqstudio.ru
Fri Mar 23 03:38:28 PDT 2007


Good time of day.

As defined in sys/proc.h process may have one of this states:

enum procstat {
        SIDL = 1,
        SACTIVE = 2,
        SSTOP = 3,
        SZOMB = 4,
};

For display summary process info 'top' use procstatenames array with values:
"", " starting, ", " running, ", " sleeping, ", " stopped, ", " zombie, "
which are not mapped to process's states.

There is a patch fo fix this promblem. It also display processes with
sleeping lwp as sleeping, for example:

37 processes:  1 running, 36 sleeping

But is more better mark process as sleeping only if _all_ of this lwps
are in sleeping state.

--- /usr/src/usr.bin/top/machine.c.orig 2007-03-22 17:03:23.000000000 +0300
+++ /usr/src/usr.bin/top/machine.c      2007-03-22 18:16:48.000000000 +0300
@@ -138,8 +138,8 @@

 int process_states[6];
 char *procstatenames[] = {
-    "", " starting, ", " running, ", " sleeping, ", " stopped, ",
-    " zombie, ",
+    "", " starting, ", " running, ", " stopped, ", " zombie, ",
+    " sleeping, ",
     NULL
 };

@@ -501,6 +501,8 @@
            (show_system || ((PP(pp, flags) & P_SYSTEM) == 0)))))
        {
            total_procs++;
+           if (LP(pp, stat) == LSSLEEP)
+               PP(pp, stat) = SZOMB + 1;
            process_states[(unsigned char) PP(pp, stat)]++;
            if ((show_threads && (LP(pp, pid) == 0)) ||
                (!show_only_threads && PP(pp, stat) != SZOMB &&

-- 
W/ best regards, Dmitry






More information about the Bugs mailing list