185 lines
3.0 KiB
HTML
185 lines
3.0 KiB
HTML
<HTML
|
|
><HEAD
|
|
><TITLE
|
|
>Load</TITLE
|
|
><META
|
|
NAME="GENERATOR"
|
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
|
|
REL="HOME"
|
|
TITLE="Bash Prompt HOWTO"
|
|
HREF="index.html"><LINK
|
|
REL="UP"
|
|
TITLE="Prompt Code Snippets"
|
|
HREF="c679.html"><LINK
|
|
REL="PREVIOUS"
|
|
TITLE="Stopped Jobs Count"
|
|
HREF="x733.html"><LINK
|
|
REL="NEXT"
|
|
TITLE="Uptime"
|
|
HREF="x758.html"></HEAD
|
|
><BODY
|
|
CLASS="SECT1"
|
|
BGCOLOR="#FFFFFF"
|
|
TEXT="#000000"
|
|
LINK="#0000FF"
|
|
VLINK="#840084"
|
|
ALINK="#0000FF"
|
|
><DIV
|
|
CLASS="NAVHEADER"
|
|
><TABLE
|
|
SUMMARY="Header navigation table"
|
|
WIDTH="100%"
|
|
BORDER="0"
|
|
CELLPADDING="0"
|
|
CELLSPACING="0"
|
|
><TR
|
|
><TH
|
|
COLSPAN="3"
|
|
ALIGN="center"
|
|
>Bash Prompt HOWTO: </TH
|
|
></TR
|
|
><TR
|
|
><TD
|
|
WIDTH="10%"
|
|
ALIGN="left"
|
|
VALIGN="bottom"
|
|
><A
|
|
HREF="x733.html"
|
|
ACCESSKEY="P"
|
|
>Prev</A
|
|
></TD
|
|
><TD
|
|
WIDTH="80%"
|
|
ALIGN="center"
|
|
VALIGN="bottom"
|
|
>Chapter 11. Prompt Code Snippets</TD
|
|
><TD
|
|
WIDTH="10%"
|
|
ALIGN="right"
|
|
VALIGN="bottom"
|
|
><A
|
|
HREF="x758.html"
|
|
ACCESSKEY="N"
|
|
>Next</A
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
><HR
|
|
ALIGN="LEFT"
|
|
WIDTH="100%"></DIV
|
|
><DIV
|
|
CLASS="SECT1"
|
|
><H1
|
|
CLASS="SECT1"
|
|
><A
|
|
NAME="AEN746"
|
|
></A
|
|
>11.7. Load</H1
|
|
><P
|
|
>The output of <B
|
|
CLASS="COMMAND"
|
|
>uptime</B
|
|
> can be used to determine both the
|
|
system load and uptime, but its output is exceptionally difficult to parse.
|
|
On a Linux system, this is made much easier to deal with by the existence
|
|
of the <TT
|
|
CLASS="FILENAME"
|
|
>/proc/</TT
|
|
> file system.
|
|
<B
|
|
CLASS="COMMAND"
|
|
>cat /proc/loadavg</B
|
|
> will show you the one minute, five
|
|
minute, and fifteen minute load average, as well as a couple other numbers
|
|
I don't know the meaning of (anyone care to fill me in?). </P
|
|
><P
|
|
>Getting the load from /proc/loadavg is easy (thanks to Jerry Peek for
|
|
reminding me of this simple method): <TT
|
|
CLASS="USERINPUT"
|
|
><B
|
|
>read one five fifteen rest
|
|
< /proc/loadavg</B
|
|
></TT
|
|
>. Just print the value you want. </P
|
|
><P
|
|
>For those without the <TT
|
|
CLASS="FILENAME"
|
|
>/proc/</TT
|
|
>
|
|
filesystem, you can use
|
|
<B
|
|
CLASS="COMMAND"
|
|
>uptime | sed -e "s/.*load average: \(.*\...\), \(.*\...\), \(.*\...\)/\1/" -e "s/ //g"</B
|
|
>
|
|
and replace "\1" with "\2" or "\3" depending if you want the one minute,
|
|
five minute, or fifteen minute load average. This is a remarkably
|
|
ugly regular expression: send suggestions if you have a better one. </P
|
|
><P
|
|
>Relative speed: 'uptime | sed -e "s/.*load average: \(.*\...\), \(.*\...\),
|
|
\(.*\...\)/\1/" -e "s/ //g" ' takes about 0.21 seconds on an unloaded 486SX25. </P
|
|
></DIV
|
|
><DIV
|
|
CLASS="NAVFOOTER"
|
|
><HR
|
|
ALIGN="LEFT"
|
|
WIDTH="100%"><TABLE
|
|
SUMMARY="Footer navigation table"
|
|
WIDTH="100%"
|
|
BORDER="0"
|
|
CELLPADDING="0"
|
|
CELLSPACING="0"
|
|
><TR
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="left"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="x733.html"
|
|
ACCESSKEY="P"
|
|
>Prev</A
|
|
></TD
|
|
><TD
|
|
WIDTH="34%"
|
|
ALIGN="center"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="index.html"
|
|
ACCESSKEY="H"
|
|
>Home</A
|
|
></TD
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="right"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="x758.html"
|
|
ACCESSKEY="N"
|
|
>Next</A
|
|
></TD
|
|
></TR
|
|
><TR
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="left"
|
|
VALIGN="top"
|
|
>Stopped Jobs Count</TD
|
|
><TD
|
|
WIDTH="34%"
|
|
ALIGN="center"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="c679.html"
|
|
ACCESSKEY="U"
|
|
>Up</A
|
|
></TD
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="right"
|
|
VALIGN="top"
|
|
>Uptime</TD
|
|
></TR
|
|
></TABLE
|
|
></DIV
|
|
></BODY
|
|
></HTML
|
|
> |