This is the mail archive of the
cygwin-patches
mailing list for the Cygwin project.
[PATCH] /proc/loadavg: add running/total processes
- From: "Yaakov (Cygwin/X)" <yselkowitz at users dot sourceforge dot net>
- To: cygwin-patches <cygwin-patches at cygwin dot com>
- Date: Tue, 29 Mar 2011 19:32:12 -0500
- Subject: [PATCH] /proc/loadavg: add running/total processes
This patch adds the fourth component of Linux's /proc/loadavg[1], the
current running/total processes count. My only question is if states
other than 'O' and 'R' should be considered "running" for this purpose.
Patches for winsup/cygwin and winsup/doc attached.
Yaakov
[1] http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/4/html/Reference_Guide/s2-proc-loadavg.html
2011-03-29 Yaakov Selkowitz <yselkowitz@users.sourceforge.net>
* fhandler_proc.cc (format_proc_loadavg): Add running/total
processes as fourth component of output.
* fhandler_process.cc (get_process_state): Make non-static.
Index: fhandler_proc.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/fhandler_proc.cc,v
retrieving revision 1.95
diff -u -r1.95 fhandler_proc.cc
--- fhandler_proc.cc 17 Jan 2011 14:31:30 -0000 1.95
+++ fhandler_proc.cc 23 Feb 2011 05:44:03 -0000
@@ -379,9 +379,21 @@
static _off64_t
format_proc_loadavg (void *, char *&destbuf)
{
+ extern int get_process_state (DWORD dwProcessId);
+ unsigned running = 0;
+ winpids pids ((DWORD) 0);
+
+ for (unsigned i = 0; i < pids.npids; i++)
+ switch (get_process_state (i)) {
+ case 'O':
+ case 'R':
+ running++;
+ break;
+ }
+
destbuf = (char *) crealloc_abort (destbuf, 16);
- return __small_sprintf (destbuf, "%u.%02u %u.%02u %u.%02u\n",
- 0, 0, 0, 0, 0, 0);
+ return __small_sprintf (destbuf, "%u.%02u %u.%02u %u.%02u %u/%u\n",
+ 0, 0, 0, 0, 0, 0, running, pids.npids);
}
static _off64_t
Index: fhandler_process.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/fhandler_process.cc,v
retrieving revision 1.93
diff -u -r1.93 fhandler_process.cc
--- fhandler_process.cc 13 Sep 2010 13:02:19 -0000 1.93
+++ fhandler_process.cc 23 Feb 2011 05:44:03 -0000
@@ -79,8 +79,7 @@
static const int PROCESS_LINK_COUNT =
(sizeof (process_tab) / sizeof (virt_tab_t)) - 1;
-
-static int get_process_state (DWORD dwProcessId);
+int get_process_state (DWORD dwProcessId);
static bool get_mem_values (DWORD dwProcessId, unsigned long *vmsize,
unsigned long *vmrss, unsigned long *vmtext,
unsigned long *vmdata, unsigned long *vmlib,
@@ -928,7 +927,7 @@
return len;
}
-static int
+int
get_process_state (DWORD dwProcessId)
{
/*
2011-03-29 Yaakov Selkowitz <yselkowitz@users.sourceforge.net>
* new-features.sgml (ov-new1.7.10): /proc/loadavg now shows
current running/total processes count.
Index: new-features.sgml
===================================================================
RCS file: /cvs/src/src/winsup/doc/new-features.sgml,v
retrieving revision 1.69
diff -u -r1.69 new-features.sgml
--- new-features.sgml 29 Mar 2011 10:35:08 -0000 1.69
+++ new-features.sgml 30 Mar 2011 00:12:53 -0000
@@ -9,6 +9,11 @@
pthread_spin_lock, pthread_spin_trylock, pthread_spin_unlock.
</para></listitem>
+<listitem><para>
+/proc/loadavg now shows the number of currently running processes and the
+total number of processes.
+</para></listitem>
+
</itemizedlist>
</sect2>