242 lines
10 KiB
HTML
242 lines
10 KiB
HTML
<!--startcut ======================================================= -->
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
|
<html>
|
|
<head>
|
|
<META NAME="generator" CONTENT="lgazmail v1.3D.j">
|
|
<TITLE>The Answer Guy 54: Use the Sources, Dude!</TITLE>
|
|
</HEAD><BODY BGCOLOR="#FFFFFF" TEXT="#000000"
|
|
LINK="#3366FF" VLINK="#A000A0">
|
|
<!-- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
|
|
<P> <hr>
|
|
<!-- *** BEGIN navbar *** :::::::::::::::::::::::::::::::::::::::::::::::: -->
|
|
<p align="center">
|
|
<A HREF="../lg_bytes54.html"><IMG ALT="[ Prev ]"
|
|
SRC="../../gx/navbar/prev.jpg"
|
|
WIDTH="16" HEIGHT="45" BORDER="0" ALIGN="bottom"></A>
|
|
<IMG ALT="" SRC="../../gx/navbar/left.jpg"
|
|
WIDTH="14" HEIGHT="45" BORDER="0" ALIGN="bottom" >
|
|
<A HREF="../index.html"><IMG ALT="[ Table of Contents ]"
|
|
SRC="../../gx/navbar/toc.jpg"
|
|
WIDTH="220" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A>
|
|
<A HREF="../../index.html"><IMG ALT="[ Front Page ]"
|
|
SRC="../../gx/navbar/frontpage.jpg"
|
|
WIDTH="137" HEIGHT="45" BORDER="0" ALIGN="bottom"></A>
|
|
<A HREF="../../faq/index.html"><IMG ALT="[ FAQ ]"
|
|
SRC="../../gx/navbar/faq.jpg"
|
|
WIDTH="62" HEIGHT="45" BORDER="0" ALIGN="bottom"></A>
|
|
<IMG ALT="" SRC="../../gx/navbar/right.jpg"
|
|
WIDTH="15" HEIGHT="45" ALIGN="bottom" >
|
|
<A HREF="../lg_tips54.html"><IMG ALT="[ Next ]"
|
|
SRC="../../gx/navbar/next.jpg"
|
|
WIDTH="15" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A>
|
|
<!-- *** END navbar *** :::::::::::::::::::::::::::::::::::::::::::::::::: -->
|
|
</p>
|
|
<P> <hr> <P>
|
|
<!-- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
|
|
<center>
|
|
<H1><A NAME="answer">
|
|
<img src="../../gx/dennis/qbubble.gif" alt="(?)"
|
|
border="0" align="middle">
|
|
<font color="#B03060">The Answer Guy</font>
|
|
<img src="../../gx/dennis/bbubble.gif" alt="(!)"
|
|
border="0" align="middle">
|
|
</A></H1>
|
|
<BR>
|
|
<H4>By James T. Dennis,
|
|
<a href="mailto:linux-questions-only@ssc.com">linux-questions-only@ssc.com</a><BR>
|
|
LinuxCare,
|
|
<A HREF="http://www.linuxcare.com/">http://www.linuxcare.com/</A>
|
|
</H4>
|
|
</center>
|
|
|
|
<p><hr><p>
|
|
<!-- endcut ======================================================= -->
|
|
<!-- begin 13 -->
|
|
<H3 align="left"><img src="../../gx/dennis/qbubble.gif"
|
|
height="50" width="60" alt="(?) " border="0"
|
|
>Use the Sources, Dude!</H3>
|
|
|
|
|
|
<p><strong>From pundu on Wed, 10 May 2000
|
|
</strong></p>
|
|
<!-- ::
|
|
Use the Sources, Dude!
|
|
~~~~~~~~~~~~~~~~~~~~~~
|
|
:: -->
|
|
<P><STRONG>
|
|
Hi,
|
|
</STRONG></P>
|
|
<P><STRONG>
|
|
I would like to know how one can calculate cpu load and memory
|
|
</STRONG></P>
|
|
<P><STRONG>
|
|
used by processes as shown by 'top' command. It would be nice if any
|
|
one can explain me how you could do these by writing your own
|
|
programs , or by any other means.
|
|
</STRONG></P>
|
|
<BLOCKQUOTE><IMG SRC="../../gx/dennis/bbub.gif" ALT="(!)"
|
|
HEIGHT="28" WIDTH="50" BORDER="0"
|
|
>
|
|
Why don't you download the sources to 'top' and 'uptime'
|
|
and read them? On a reasonably modern <A HREF="http://www.debian.org/">Debian</A> system you could
|
|
just issue the command 'apt-get source procps' to have your system
|
|
find, fetch, unpack and patch those. ('top', 'uptime',
|
|
'kill' and a number of other process management commands are in
|
|
the "procps" package <TT>---</TT> since these are all tools that implement
|
|
process management and reporting using the <TT>/proc</TT> kernel support.
|
|
</BLOCKQUOTE>
|
|
<BLOCKQUOTE>
|
|
(Technically there were/are other ways to do these sorts of process
|
|
management things, in cases where you don't have <TT>/proc</TT> enabled <TT>---</TT>
|
|
but they are no widely used anymore. There is a <TT>/proc</TT> alternative
|
|
that's implemented as a device driver <TT>---</TT> for embedded systems, and
|
|
there's some old techniques for doing it by reading some of the
|
|
kernel's data structures though <TT>/dev/kmem</TT> <TT>---</TT> basically by using root
|
|
level read access to wander around the kernels memory extracting and
|
|
parsing bits of it from all over).
|
|
</BLOCKQUOTE>
|
|
<BLOCKQUOTE>
|
|
Your distribution probably came with sources (maybe on an extra CD)
|
|
or you could always wander around Metalab (formerly known as Sunsite)
|
|
<A HREF="http://metalab.unc.edu/pub/Linux"
|
|
>http://metalab.unc.edu/pub/Linux</A> to find lots of source code for
|
|
lots of Linux stuff. You might also look at Freshmeat
|
|
(<A HREF="http://www.freshmeat.net"
|
|
>http://www.freshmeat.net</A>), Appwatch (<A HREF="http://www.appwatch.com"
|
|
>http://www.appwatch.com</A>) and
|
|
even ExecPC's LSM (Linux Software Map) at <A HREF="http://www.execpc.com/lsm"
|
|
>http://www.execpc.com/lsm</A>
|
|
(You can even get 'appindex' a little curses package which can help
|
|
you find apps from Freshmeat and the LSM by downloading RSS files
|
|
from each of them on demand).
|
|
</BLOCKQUOTE>
|
|
|
|
<p><em>[ As of publication time, there's another one, called IceWALKERS
|
|
(<a href="http://www.icewalk.com/">www.icewalk.com</a>)
|
|
-- Heather ]</em></p>
|
|
<BLOCKQUOTE>
|
|
Another good site to find the sources to your free software is
|
|
the "Official GNU Web site" (<A HREF="http://www.gnu.org"
|
|
>http://www.gnu.org</A>) and at the
|
|
old GNU master archive site: <A HREF="ftp://prep.ai.mit.edu/gnu"
|
|
>ftp://prep.ai.mit.edu/gnu</A>
|
|
</BLOCKQUOTE>
|
|
<BLOCKQUOTE>
|
|
Of course you could always compare these sources to those from
|
|
another free implemention of UNIX. Look at the FreeBSD web site
|
|
(<A HREF="http://www.freebsd.org"
|
|
>http://www.freebsd.org</A>) and its ilk (OpenBSD
|
|
<A HREF="http://www.openbsd.org"
|
|
>http://www.openbsd.org</A>
|
|
and NetBSD <A HREF="http://www.netbsd.org"
|
|
>http://www.netbsd.org</A>).
|
|
</BLOCKQUOTE>
|
|
<BLOCKQUOTE>
|
|
Of course I realize that you might not have realized that the source
|
|
code was available. That's one of the features of Linux that you may
|
|
have heard touted in the press. That "open source" thing means you
|
|
can look at the sources to any of the core systems and packages (from
|
|
the kernel, and libraries, through the compilers and the rest of the
|
|
tool chain, and down into most of the utilities and applications).
|
|
</BLOCKQUOTE>
|
|
<BLOCKQUOTE>
|
|
I also realize that many people have no idea how to find these
|
|
sources. Obviously the first step is to find out what package the
|
|
program you what to look at came from. Under any of the RPM based
|
|
systems (<A HREF="http://www.suse.com/">S.u.S.E.</A> <A HREF="http://www.redhat.com/">Red Hat</A>, <A HREF="http://www.turbolinux.com/">TurboLinux</A>, <A HREF="http://www.caldera.com/">Caldera</A> OpenLinux, etc) you
|
|
can use a command like 'rpm <TT>-qf</TT> <TT>/usr/bin/top</TT>' to find out that 'top'
|
|
is part of the procps package. Under Debian you could install the
|
|
dlocate package, or use a command like 'grep <TT>/usr/bin/top</TT>
|
|
<TT>/var/lib/dpkg/info/*.list</TT>' or one like 'dpkg <TT>-S</TT> bin/top' (note I
|
|
don't need a full path in that case). All of these will give you a
|
|
package name (procps in this case). Then you can use the techniques
|
|
and web sites I've mentioned above to find the package sources.
|
|
</BLOCKQUOTE>
|
|
<BLOCKQUOTE>
|
|
Incidentally the canonical (master) URL for procps seems to be:
|
|
</BLOCKQUOTE>
|
|
<BLOCKQUOTE><BLOCKQuote>
|
|
<A HREF="ftp://people.redhat.com/johnsonm/procps/procps-2.0.6.tar.gz"
|
|
>ftp://people.redhat.com/johnsonm/procps/procps-2.0.6.tar.gz</A>
|
|
</BLOCKQuote></BLOCKQUOTE>
|
|
<BLOCKQUOTE>
|
|
... according to the Appindex and LSM entries I read).
|
|
</BLOCKQUOTE>
|
|
|
|
<!-- sig -->
|
|
|
|
|
|
<!-- end 13 -->
|
|
<!--startcut ======================================================= -->
|
|
<P> <hr> </p>
|
|
<H5 align="center"><a href="http://www.linuxgazette.com/copying.html"
|
|
>Copyright ©</a> 2000, James T. Dennis
|
|
<BR>Published in <I>The Linux Gazette</I> Issue 54 June 2000</H5>
|
|
<H6 ALIGN="center">HTML transformation by
|
|
<A HREF="mailto:star@tuxtops.com">Heather Stern</a> of
|
|
Tuxtops, Inc.,
|
|
<A HREF="http://www.tuxtops.com/">http://www.tuxtops.com/</A>
|
|
</H6>
|
|
<P> <hr>
|
|
<!-- begin tagnav ::::::::::::::::::::::::::::::::::::::::::::::::::-->
|
|
<p align="center">
|
|
<IMG ALT="" SRC="../../gx/navbar/left.jpg"
|
|
WIDTH="14" HEIGHT="45" BORDER="0" ALIGN="middle" border="0">
|
|
<A HREF="../lg_answer54.html"
|
|
><IMG SRC="../../gx/dennis/answertoc.jpg" align="middle"
|
|
ALT="[ Answer Guy Current Index ]" border="0"></A>
|
|
<A HREF="../lg_answer54.html#greeting"><img align="middle"
|
|
src="../../gx/dennis/smily.gif" alt="greetings" border="0"></A>
|
|
<A HREF="1.html">1</A>
|
|
<A HREF="2.html">2</A>
|
|
<A HREF="3.html">3</A>
|
|
<A HREF="4.html">4</A>
|
|
<A HREF="5.html">5</A>
|
|
<A HREF="6.html">6</A>
|
|
<A HREF="7.html">7</A>
|
|
<A HREF="8.html">8</A>
|
|
<A HREF="9.html">9</A>
|
|
<A HREF="10.html">10</A>
|
|
<A HREF="11.html">11</A>
|
|
<A HREF="12.html">12</A>
|
|
<A HREF="13.html">13</A>
|
|
<A HREF="14.html">14</A>
|
|
<A HREF="15.html">15</A>
|
|
<A HREF="16.html">16</A>
|
|
<A HREF="17.html">17</A>
|
|
<A HREF="18.html">18</A>
|
|
<A HREF="../../tag/kb.html"
|
|
><IMG SRC="../../gx/dennis/answerpast.jpg" align="middle"
|
|
ALT="[ Index of Past Answers ]" border="0"></A></td>
|
|
<IMG ALT="" SRC="../../gx/navbar/right.jpg" align="middle"
|
|
WIDTH="14" HEIGHT="45" BORDER="0">
|
|
</p>
|
|
<!-- end tagnav ::::::::::::::::::::::::::::::::::::::::::::::::::::-->
|
|
<P> <hr>
|
|
<!-- *** BEGIN navbar *** :::::::::::::::::::::::::::::::::::::::::::::::: -->
|
|
<p align="center">
|
|
<A HREF="../lg_bytes54.html"><IMG ALT="[ Prev ]"
|
|
SRC="../../gx/navbar/prev.jpg"
|
|
WIDTH="16" HEIGHT="45" BORDER="0" ALIGN="bottom"></A>
|
|
<IMG ALT="" SRC="../../gx/navbar/left.jpg"
|
|
WIDTH="14" HEIGHT="45" BORDER="0" ALIGN="bottom" >
|
|
<A HREF="../index.html"><IMG ALT="[ Table of Contents ]"
|
|
SRC="../../gx/navbar/toc.jpg"
|
|
WIDTH="220" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A>
|
|
<A HREF="../../index.html"><IMG ALT="[ Front Page ]"
|
|
SRC="../../gx/navbar/frontpage.jpg"
|
|
WIDTH="137" HEIGHT="45" BORDER="0" ALIGN="bottom"></A>
|
|
<A HREF="../../faq/index.html"><IMG ALT="[ FAQ ]"
|
|
SRC="../../gx/navbar/faq.jpg"
|
|
WIDTH="62" HEIGHT="45" BORDER="0" ALIGN="bottom"></A>
|
|
<IMG ALT="" SRC="../../gx/navbar/right.jpg"
|
|
WIDTH="15" HEIGHT="45" ALIGN="bottom" >
|
|
<A HREF="../lg_tips54.html"><IMG ALT="[ Next ]"
|
|
SRC="../../gx/navbar/next.jpg"
|
|
WIDTH="15" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A>
|
|
<!-- *** END navbar *** :::::::::::::::::::::::::::::::::::::::::::::::::: -->
|
|
</p>
|
|
<!-- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
|
|
</BODY></HTML>
|
|
<!--endcut ========================================================= -->
|