old-www/LDP/LG/issue46/fink.html

126 lines
8.8 KiB
HTML

<!--startcut BEGIN header ==============================================-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML><HEAD>
<title>An Overview of the Proc Filesystem LG #46</title>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#0000AF"
ALINK="#FF0000">
<!--endcut ============================================================-->
<H4>
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<H1><font color="maroon">An Overview of the Proc Filesystem</font></H1>
<H4>By <a href="mailto:jay_rf@exis.net">Jay Fink</a></H4>
</center>
<P> <HR> <P>
<!-- END header -->
One of the more interesting aspects of certain flavors of UN*X (Linux among
them) is the <CODE>/proc</CODE> filesystem. This &quot;virtual&quot; filesystem
has several key features which are interesting, useful and helpful. It can also
be dangerous and disastrous. This column will approach the <CODE>/proc</CODE>
filesystem in three areas:</P>
<OL>
<LI>A brief explanation of what it is</LI>
<LI>What <CODE>/proc</CODE> can be used for (or sometimes <B>not</B> to be used for)</LI>
<LI>A map of <CODE>/proc</CODE> as of the 2.2 Kernel on the i686 architecture</LI>
</OL>
<H2>What is <CODE>/proc</CODE>?</H2>
<P>The <CODE>/proc</CODE> filesystem is a direct <EM>reflection</EM> of the system kept in memory and represented in a hierarchal manner. The effort of the <CODE>/proc</CODE> filesystem is to provide an easy way to view kernel and information about currently running processes. As a result, some commands (ps for example) read <CODE>/proc</CODE> directly to get information about the state of the system. The premise behind <CODE>/proc</CODE> is to provide such information in a readable manner instead of having to invoke difficult to understand system calls.</P>
<H2>What <CODE>/proc</CODE> can do for an Administrator</H2>
<P>The <CODE>/proc</CODE> fs can be used for system related tasks such as:</P>
<UL>
<LI>Viewing Statistical Information</LI>
<LI>Finding out Hardware Information</LI>
<LI>Modifying Runtime Parameters</LI>
<LI>Viewing and Modifying Network and Host Parameters</LI>
<LI>Memory and Performance Information</LI>
</UL>
<P>There are some things to take note of, most of those tasks can be done with tools that either peruse <CODE>/proc</CODE> or query the kernel directly.</P>
<H3>Different Kernels = Different Capabilities</H3>
<P>Different kernels can allow for different changes and information that is presented within <CODE>/proc</CODE>. Some, all, or totally different layouts and capabilities may exist depending on your machine's kernel implementation.</P>
<H3>The Obligatory Warning</H3>
<P>Since there is no one place that documents exactly what you can and cannot do with <CODE>/proc</CODE> (again because of distro's) there is no fool-proofing it other than only root may actually descend <CODE>/proc</CODE> and monkey with the files therein. I have found the easiest approach to be a sort of hacker method - backup your kernel and apply common sense when making alterations within the <CODE>/proc</CODE> fs.</P>
<P>A prime example of tuning applications via <CODE>/proc</CODE> can be found at the <A HREF="http://www.kegel.com/c10k.html" TITLE="C10">The C10k problem</A> document at <A HREF="http://www.kegel.com/">Dan Kegel's Web Hostel</A>.</P>
<H2>A Map of <CODE>/proc</CODE></H2>
<P>Following is a table with brief descriptions of files and directories in <CODE>/proc</CODE> with the 2.2 kernel on a Linux i686 architecture.</P>
<TABLE BGCOLOR="#EEEEEE" BORDER="0" CELLPADDING="5" CELLSPACING="2" WIDTH="100%">
<TR><TD WIDTH="20%" VALIGN="top"><CODE>loadavg</CODE></TD><TD WIDTH="80%" VALIGN="top">Average of system load for the last 1, 5 and 15 minutes</TD></TR>
<TR><TD WIDTH="20%" VALIGN="top"><CODE>uptime</CODE></TD><TD WIDTH="80%" VALIGN="top">Time in seconds since boot-up and total time used by processes</TD></TR>
<TR><TD WIDTH="20%" VALIGN="top"><CODE>meminfo</CODE></TD><TD WIDTH="80%" VALIGN="top">The number of total, used and free bytes of memory and swap area(s)</TD></TR>
<TR><TD WIDTH="20%" VALIGN="top"><CODE>kmsg</CODE></TD><TD WIDTH="80%" VALIGN="top">Kernel messages that have yet to be read in by the kernel</TD></TR>
<TR><TD WIDTH="20%" VALIGN="top"><CODE>version</CODE></TD><TD WIDTH="80%" VALIGN="top">Current rev of the kernel and/or distribution (read from <CODE>linux_banner</CODE></TD></TR>
<TR><TD WIDTH="20%" VALIGN="top"><CODE>cpuinfo</CODE></TD><TD WIDTH="80%" VALIGN="top">Recognized processor parameters</TD></TR>
<TR><TD WIDTH="20%" VALIGN="top"><CODE>pci</CODE></TD><TD WIDTH="80%" VALIGN="top">Current occupation of <CODE>pci</CODE> slots.</TD></TR>
<TR><TD WIDTH="20%" VALIGN="top"><CODE>self/</CODE></TD><TD WIDTH="80%" VALIGN="top">Information about processes currently accessing <CODE>/proc</CODE></TD></TR>
<TR><TD WIDTH="20%" VALIGN="top"><CODE>net/</CODE></TD><TD WIDTH="80%" VALIGN="top">Descriptions about the network layer(s)</TD></TR>
<TR><TD WIDTH="20%" VALIGN="top"><CODE>scsi/</CODE></TD><TD WIDTH="80%" VALIGN="top">Contains files with information on individual scsi devices</TD></TR>
<TR><TD WIDTH="20%" VALIGN="top"><CODE>malloc</CODE></TD><TD WIDTH="80%" VALIGN="top">Monitoring provisions for <CODE>kmalloc</CODE> and <CODE>kfree</CODE> operations</TD></TR>
<TR><TD WIDTH="20%" VALIGN="top"><CODE>kcore</CODE></TD><TD WIDTH="80%" VALIGN="top">A core dump for the kernel (memory snapshot)</TD></TR>
<TR><TD WIDTH="20%" VALIGN="top"><CODE>modules</CODE></TD><TD WIDTH="80%" VALIGN="top">Information regarding single loaded modules</TD></TR>
<TR><TD WIDTH="20%" VALIGN="top"><CODE>stat</CODE></TD><TD WIDTH="80%" VALIGN="top">General Linux Statistics</TD></TR>
<TR><TD WIDTH="20%" VALIGN="top"><CODE>devices</CODE></TD><TD WIDTH="80%" VALIGN="top">Information about kernel registered devices on the system</TD></TR>
<TR><TD WIDTH="20%" VALIGN="top"><CODE>interrupts</CODE></TD><TD WIDTH="80%" VALIGN="top">Interrupt assignment information</TD></TR>
<TR><TD WIDTH="20%" VALIGN="top"><CODE>filesystems</CODE></TD><TD WIDTH="80%" VALIGN="top">Existing filesystem implementations</TD></TR>
<TR><TD WIDTH="20%" VALIGN="top"><CODE>ksyms</CODE></TD><TD WIDTH="80%" VALIGN="top">Symbols exported by the kernel</TD></TR>
<TR><TD WIDTH="20%" VALIGN="top"><CODE>dma</CODE></TD><TD WIDTH="80%" VALIGN="top">Occupied DMA channels</TD></TR>
<TR><TD WIDTH="20%" VALIGN="top"><CODE>ioports</CODE></TD><TD WIDTH="80%" VALIGN="top">Currently occupied IO ports</TD></TR>
<TR><TD WIDTH="20%" VALIGN="top"><CODE>smp</CODE></TD><TD WIDTH="80%" VALIGN="top">Individual information about CPU's if SMP is enabled</TD></TR>
<TR><TD WIDTH="20%" VALIGN="top"><CODE>cmdline</CODE></TD><TD WIDTH="80%" VALIGN="top">Command line parameters passed to the kernel at boot time</TD></TR>
<TR><TD WIDTH="20%" VALIGN="top"><CODE>sys/</CODE></TD><TD WIDTH="80%" VALIGN="top">Important kernel and network information</TD></TR>
<TR><TD WIDTH="20%" VALIGN="top"><CODE>mtab</CODE></TD><TD WIDTH="80%" VALIGN="top">Currently mounted filesystems</TD></TR>
<TR><TD WIDTH="20%" VALIGN="top"><CODE>md</CODE></TD><TD WIDTH="80%" VALIGN="top">Multiple device driver information (if enabled)</TD></TR>
<TR><TD WIDTH="20%" VALIGN="top"><CODE>rc</CODE></TD><TD WIDTH="80%" VALIGN="top">Enhanced real time clock (if enabled)</TD></TR>
<TR><TD WIDTH="20%" VALIGN="top"><CODE>locks</CODE></TD><TD WIDTH="80%" VALIGN="top">Currently locked files</TD></TR>
</TABLE>
<H3>Numbered Directories</H3>
<P>The number directories are running process information by PID.</P>
<H2>Results May Vary</H2>
<P>Again, keep in mind that the capabilities of /proc and it's contents do vary version to version, otherwise, happy exploring.</P>
<H2>For More Information</H2>
<P>Below is a short list of sites with in depth information (LDP aside of course) about /proc contributed by readers:</P>
<UL>
<LI><A HREF="http://skaro.nightcrawler.com/~bb/Docs/proc.html">The /proc File System</A></LI>
<LI><A HREF="http://www.kegel.com/c10k.html" TITLE="C10">The C10k problem</A></LI>
</UL>
<!-- BEGIN copyright ==================================================-->
<P> <hr> <P>
<H5 ALIGN=center>
Copyright &copy; 1999, Jay Fink<BR>
Published in Issue 46 of <i>Linux Gazette</i>, October 1999</H5>
<!-- END copyright ===================================================-->
<!--startcut footer ===================================================-->
<P> <hr> <P>
<A HREF="index.html"><IMG ALIGN=BOTTOM SRC="../gx/indexnew.gif"
ALT="[ TABLE OF CONTENTS ]"></A>
<A HREF="../index.html"><IMG ALIGN=BOTTOM SRC="../gx/homenew.gif"
ALT="[ FRONT PAGE ]"></A>
<A HREF="fauthoux.html"><IMG SRC="../gx/back2.gif"
ALT=" Back "></A>
<A HREF="../faq/index.html"
><IMG SRC="./../gx/dennis/faq.gif"
ALT="[ Linux Gazette FAQ ]"></A>
<A HREF="gm.html"><IMG SRC="../gx/fwd.gif" ALT=" Next "></A>
<P> <hr> <P>
</BODY></HTML>
<!--endcut ============================================================-->