kernel patch for /proc/stat addition

Phil Schwan (pschwan@apk.net)
Tue, 26 Aug 1997 19:22:37 -0400 (EDT)


In the end, this seemed the easiest and most sensible way of handling the
counting of zombied, sleeping, running, stopped, etc. processes. This patch
may not have the most tight code, so those of you who know a bit more about
hand-optimizing may want to do something with it. It's a very small patch,
patched against 2.0.31p7, but I believe it'll apply cleanly to 2.0.29 and
above. Feedback is appreciated, let me know what I'm doing wrong, if there's
something :) What sort of chance of getting into the kernel does this have?

Phil

--------------------------------------------------------------------------
'The ultimate seal on any software product is not any sort of kite mark or
standards conformance certificate, it's that label that says, "Destruction
tested by Alan Cox.... Survived."' -- Clive Dolphin (3Com PDD)

--- linux/fs/proc/array.c Sun Aug 24 15:58:04 1997
+++ linux/fs/proc/array.c.new Sun Aug 24 14:14:54 1997
@@ -24,10 +24,13 @@
* <Jeff_Tranter@Mitel.COM>
*
* Bruno Haible : remove 4K limit for the maps file
- * <haible@ma2s2.mathematik.uni-karlsruhe.de>
+ * <haible@ma2s2.mathematik.uni-karlsruhe.de>
*
* Yves Arrouye : remove removal of trailing spaces in get_array.
* <Yves.Arrouye@marin.fdn.fr>
+ *
+ * Phil Schwan : added prstcnts line to /proc/stat
+ * <pschwan@apk.net>
*/

#include <linux/types.h>
@@ -193,7 +196,7 @@
static int get_kstat(char * buffer)
{
int i, len;
- unsigned sum = 0;
+ unsigned sleeping=0, zombie=0, stopped=0, running=0, disk_sleep=0, paging=0, sum=0;
extern unsigned long total_forks;

for (i = 0 ; i < NR_IRQS ; i++)
@@ -227,15 +230,44 @@
kstat.pswpin,
kstat.pswpout,
sum);
+ for (i = 1; i < NR_TASKS; i++) {
+ if (task[i] != NULL) {
+ switch(task[i]->state) {
+ case 0:
+ running++;
+ break;
+ case 1:
+ sleeping++;
+ break;
+ case 2:
+ disk_sleep++;
+ break;
+ case 3:
+ zombie++;
+ break;
+ case 4:
+ stopped++;
+ break;
+ case 5:
+ paging++;
+ break;
+ default:
+ /* eh!? */
+ }
+ }
+ }
+
for (i = 0 ; i < NR_IRQS ; i++)
len += sprintf(buffer + len, " %u", kstat.interrupts[i]);
len += sprintf(buffer + len,
"\nctxt %u\n"
"btime %lu\n"
- "processes %lu\n",
+ "processes %lu\n"
+ "prstcnts %u %u %u %u %u %u\n",
kstat.context_swtch,
xtime.tv_sec - jiffies / HZ,
- total_forks);
+ total_forks, running, sleeping, disk_sleep,
+ zombie, stopped, paging);
return len;
}