a way to read the current cpu load from the shell or via a cmdline utility in cygwin?
Igor Pechtchanski
pechtcha@cs.nyu.edu
Thu Jul 25 06:01:00 GMT 2002
On Wed, 24 Jul 2002, Jim George wrote:
> On Wed, 24 Jul 2002 08:41:05 +0100 (BST)
> John Morrison <john.r.morrison@ntlworld.com> wrote:
>
> > Does cat /proc/stat | grep cpu give you the information you want?
> >
> > J.
> >
> > On Wed, 24 Jul 2002, Dylan Cuthbert wrote:
> > > Hi there,
> > >
> > > I've searched through the archives but can't seem to find any mention of
> > > this, is there a way to display the cpu load via a shell utility?
> > >
> > > If not, can someone point me to the posix function call (if it exists) so I
> > > can write a little utility. I want to do some load balanced compiles across
> > > several machines by spawning the compile across the network via "make -j",
> > > and a wrapper for gcc, then use rsh (ssh or rexec) and network sharing to do
> > > the compile. The thing is I only want to use machines whose loads are low.
> > >
> > > Of course, if a tool for this kind of thing already exists, then please give
> > > me a pointer.
> > >
> > > Regards
> > >
> > > ---------------------------------
> > > Q-Games, Dylan Cuthbert.
> > > http://www.q-games.com
> Under Linux we had 'top'. Is there an equivalent or something that
> someone is working on?
> Jim
Jim,
I did a google search on "linux top cpu load". Here's a top from the
first match: http://www.groupsys.com/topsrc/top-3.5beta9.tar.gz
It took about an hour to make it compile and run under cygwin 1.3.12-2 on
Win2k. The patch is attached.
Note: I just compiled and ran the code; I haven't verified the correctness
of the output. It seemed to work without crashing, and the output looked
plausible. I also haven't tested it on any system other than mine (above).
Try it at your own risk.
Igor
--
http://cs.nyu.edu/~pechtcha/
|\ _,,,---,,_ pechtcha@cs.nyu.edu
ZZZzz /,`.-'`' -. ;-;;,_ igor@watson.ibm.com
|,4- ) )-,_. ,\ ( `'-' Igor Pechtchanski
'---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow!
It took the computational power of three Commodore 64s to fly to the moon.
It takes a 486 to run Windows 95. Something is wrong here. -- SC sig file
-------------- next part --------------
diff -N -c -r -x .defaults ../top-3.5beta9/Configure ./Configure
*** ../top-3.5beta9/Configure Fri Dec 18 10:42:29 1998
--- ./Configure Wed Jul 24 22:36:44 2002
***************
*** 503,509 ****
-e "s|%topn%|$topn|" \
-e "s|%delay%|$delay|" \
-e "s|%random%|$random|" \
! top.local.H >top.local.h
echo "Building top.1..."
sed -e "s|%topn%|$topn|" \
--- 503,509 ----
-e "s|%topn%|$topn|" \
-e "s|%delay%|$delay|" \
-e "s|%random%|$random|" \
! top.local.h.X >top.local.h
echo "Building top.1..."
sed -e "s|%topn%|$topn|" \
diff -N -c -r -x .defaults ../top-3.5beta9/Makefile.X ./Makefile.X
*** ../top-3.5beta9/Makefile.X Tue Nov 19 21:19:24 1996
--- ./Makefile.X Wed Jul 24 22:37:21 2002
***************
*** 63,69 ****
@echo 'You need to run the script "Configure" before running "make".'
exit 10
! top.local.h: top.local.H
@echo 'You need to run the script "Configure" before running "make".'
exit 10
--- 63,69 ----
@echo 'You need to run the script "Configure" before running "make".'
exit 10
! top.local.h: top.local.h.X
@echo 'You need to run the script "Configure" before running "make".'
exit 10
diff -N -c -r -x .defaults ../top-3.5beta9/commands.c ./commands.c
*** ../top-3.5beta9/commands.c Wed Jul 1 15:30:08 1998
--- ./commands.c Wed Jul 24 22:49:36 2002
***************
*** 446,451 ****
--- 446,452 ----
char *str;
{
+ #if defined(PRIO_PROCESS)
register char negate;
int prio;
int procnum;
***************
*** 502,507 ****
--- 503,509 ----
ERROR(str, errno);
}
} while ((str = next_field(str)) != NULL);
+ #endif
/* return appropriate error string */
return(err_string());
diff -N -c -r -x .defaults ../top-3.5beta9/machine/m_linux.c ./machine/m_linux.c
*** ../top-3.5beta9/machine/m_linux.c Wed Jul 1 15:32:49 1998
--- ./machine/m_linux.c Wed Jul 24 23:15:42 2002
***************
*** 34,47 ****
--- 34,61 ----
#include <sys/vfs.h>
#include <sys/param.h> /* for HZ */
+
+ #if 0
#include <asm/page.h> /* for PAGE_SHIFT */
+ #else
+ #define PAGE_SHIFT 12
+ #endif
+
+ #if 0
#include <linux/tasks.h> /* for NR_TASKS */
+ #else
+ #define NR_TASKS 1<<12
+ #endif
#if 0
#include <linux/proc_fs.h> /* for PROC_SUPER_MAGIC */
#else
+ #ifdef __CYGWIN__
+ #define PROC_SUPER_MAGIC 0x700ff
+ #else
#define PROC_SUPER_MAGIC 0x9fa0
#endif
+ #endif
#define PROCFS "/proc"
extern char *myname;
***************
*** 156,161 ****
--- 170,176 ----
{
fprintf(stderr, "%s: proc filesystem not mounted on " PROCFS "\n",
myname);
+ fprintf(stderr, " type=%x\n", sb.f_type);
return -1;
}
}
diff -N -c -r -x .defaults ../top-3.5beta9/top.c ./top.c
*** ../top-3.5beta9/top.c Wed Jul 1 15:41:03 1998
--- ./top.c Wed Jul 24 23:11:00 2002
***************
*** 143,149 ****
--- 143,153 ----
static char tempbuf1[50];
static char tempbuf2[50];
+ #if 0
int old_sigmask; /* only used for BSD-style signals */
+ #else
+ sigset_t sigmask, old_sigmask;
+ #endif
int topn = Default_TOPN;
int delay = Default_DELAY;
int displays = 0; /* indicates unspecified */
***************
*** 489,495 ****
--- 493,507 ----
sighold(SIGQUIT);
sighold(SIGTSTP);
#else
+ #if 0
old_sigmask = sigblock(Smask(SIGINT) | Smask(SIGQUIT) | Smask(SIGTSTP));
+ #else
+ (void) sigemptyset(&sigmask);
+ (void) sigaddset(&sigmask, SIGINT);
+ (void) sigaddset(&sigmask, SIGQUIT);
+ (void) sigaddset(&sigmask, SIGTSTP);
+ (void) sigprocmask(SIG_BLOCK, &sigmask, &old_sigmask);
+ #endif
#endif
init_screen();
(void) signal(SIGINT, leave);
***************
*** 503,509 ****
--- 515,525 ----
sigrelse(SIGQUIT);
sigrelse(SIGTSTP);
#else
+ #if 0
(void) sigsetmask(old_sigmask);
+ #else
+ (void) sigprocmask(SIG_SETMASK, &old_sigmask, (sigset_t*)NULL);
+ #endif
#endif
if (warnings)
{
***************
*** 940,945 ****
--- 956,963 ----
int i;
{
+ sigset_t sigmask;
+
/* move to the lower left */
end_screen();
fflush(stdout);
***************
*** 951,957 ****
--- 969,981 ----
#ifdef SIGRELSE
sigrelse(SIGTSTP);
#else
+ #if 0
(void) sigsetmask(sigblock(0) & ~(1 << (SIGTSTP - 1)));
+ #else
+ (void) sigemptyset(&sigmask);
+ (void) sigaddset(&sigmask, SIGTSTP);
+ (void) sigprocmask(SIG_UNBLOCK, &sigmask, (sigset_t*)NULL);
+ #endif
#endif
(void) kill(0, SIGTSTP);
diff -N -c -r -x .defaults ../top-3.5beta9/top.local.H ./top.local.H
*** ../top-3.5beta9/top.local.H Wed Apr 15 13:30:57 1992
--- ./top.local.H Wed Dec 31 19:00:00 1969
***************
*** 1,68 ****
- /*
- * Top - a top users display for Berkeley Unix
- *
- * Definitions for things that might vary between installations.
- */
-
- /*
- * The space command forces an immediate update. Sometimes, on loaded
- * systems, this update will take a significant period of time (because all
- * the output is buffered). So, if the short-term load average is above
- * "LoadMax", then top will put the cursor home immediately after the space
- * is pressed before the next update is attempted. This serves as a visual
- * acknowledgement of the command. On Suns, "LoadMax" will get multiplied by
- * "FSCALE" before being compared to avenrun[0]. Therefore, "LoadMax"
- * should always be specified as a floating point number.
- */
- #ifndef LoadMax
- #define LoadMax %LoadMax%
- #endif
-
- /*
- * "Table_size" defines the size of the hash tables used to map uid to
- * username. The number of users in /etc/passwd CANNOT be greater than
- * this number. If the error message "table overflow: too many users"
- * is printed by top, then "Table_size" needs to be increased. Things will
- * work best if the number is a prime number that is about twice the number
- * of lines in /etc/passwd.
- */
- #ifndef Table_size
- #define Table_size %TableSize%
- #endif
-
- /*
- * "Nominal_TOPN" is used as the default TOPN when Default_TOPN is Infinity
- * and the output is a dumb terminal. If we didn't do this, then
- * installations who use a default TOPN of Infinity will get every
- * process in the system when running top on a dumb terminal (or redirected
- * to a file). Note that Nominal_TOPN is a default: it can still be
- * overridden on the command line, even with the value "infinity".
- */
- #ifndef Nominal_TOPN
- #define Nominal_TOPN %NominalTopn%
- #endif
-
- #ifndef Default_TOPN
- #define Default_TOPN %topn%
- #endif
-
- #ifndef Default_DELAY
- #define Default_DELAY %delay%
- #endif
-
- /*
- * If the local system's getpwnam interface uses random access to retrieve
- * a record (i.e.: 4.3 systems, Sun "yellow pages"), then defining
- * RANDOM_PW will take advantage of that fact. If RANDOM_PW is defined,
- * then getpwnam is used and the result is cached. If not, then getpwent
- * is used to read and cache the password entries sequentially until the
- * desired one is found.
- *
- * We initially set RANDOM_PW to something which is controllable by the
- * Configure script. Then if its value is 0, we undef it.
- */
-
- #define RANDOM_PW %random%
- #if RANDOM_PW == 0
- #undef RANDOM_PW
- #endif
--- 0 ----
diff -N -c -r -x .defaults ../top-3.5beta9/top.local.h.X ./top.local.h.X
*** ../top-3.5beta9/top.local.h.X Wed Dec 31 19:00:00 1969
--- ./top.local.h.X Wed Apr 15 13:30:57 1992
***************
*** 0 ****
--- 1,68 ----
+ /*
+ * Top - a top users display for Berkeley Unix
+ *
+ * Definitions for things that might vary between installations.
+ */
+
+ /*
+ * The space command forces an immediate update. Sometimes, on loaded
+ * systems, this update will take a significant period of time (because all
+ * the output is buffered). So, if the short-term load average is above
+ * "LoadMax", then top will put the cursor home immediately after the space
+ * is pressed before the next update is attempted. This serves as a visual
+ * acknowledgement of the command. On Suns, "LoadMax" will get multiplied by
+ * "FSCALE" before being compared to avenrun[0]. Therefore, "LoadMax"
+ * should always be specified as a floating point number.
+ */
+ #ifndef LoadMax
+ #define LoadMax %LoadMax%
+ #endif
+
+ /*
+ * "Table_size" defines the size of the hash tables used to map uid to
+ * username. The number of users in /etc/passwd CANNOT be greater than
+ * this number. If the error message "table overflow: too many users"
+ * is printed by top, then "Table_size" needs to be increased. Things will
+ * work best if the number is a prime number that is about twice the number
+ * of lines in /etc/passwd.
+ */
+ #ifndef Table_size
+ #define Table_size %TableSize%
+ #endif
+
+ /*
+ * "Nominal_TOPN" is used as the default TOPN when Default_TOPN is Infinity
+ * and the output is a dumb terminal. If we didn't do this, then
+ * installations who use a default TOPN of Infinity will get every
+ * process in the system when running top on a dumb terminal (or redirected
+ * to a file). Note that Nominal_TOPN is a default: it can still be
+ * overridden on the command line, even with the value "infinity".
+ */
+ #ifndef Nominal_TOPN
+ #define Nominal_TOPN %NominalTopn%
+ #endif
+
+ #ifndef Default_TOPN
+ #define Default_TOPN %topn%
+ #endif
+
+ #ifndef Default_DELAY
+ #define Default_DELAY %delay%
+ #endif
+
+ /*
+ * If the local system's getpwnam interface uses random access to retrieve
+ * a record (i.e.: 4.3 systems, Sun "yellow pages"), then defining
+ * RANDOM_PW will take advantage of that fact. If RANDOM_PW is defined,
+ * then getpwnam is used and the result is cached. If not, then getpwent
+ * is used to read and cache the password entries sequentially until the
+ * desired one is found.
+ *
+ * We initially set RANDOM_PW to something which is controllable by the
+ * Configure script. Then if its value is 0, we undef it.
+ */
+
+ #define RANDOM_PW %random%
+ #if RANDOM_PW == 0
+ #undef RANDOM_PW
+ #endif
-------------- next part --------------
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
More information about the Cygwin
mailing list