📄 ch58.htm
字号:
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<font face="Arial,Helvetica" size="-1" color="#006666">
<b>Linux</b></font><p>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<UL>
<LI><A HREF="#Heading1">- 58 -</A>
<UL>
<LI><A HREF="#Heading2">The Pseudo File System</A>
<UL>
<LI><A HREF="#Heading3">Listing 58.1. A typical listing of /proc.</A>
<LI><A HREF="#Heading4">Looking at Interrupts</A>
<LI><A HREF="#Heading5">Listing 58.2. Show the interrupts in the system.</A>
<LI><A HREF="#Heading6">Listing the IO Ports</A>
<LI><A HREF="#Heading7">Listing 58.3. The /proc/ioports listing of IO ports on a
Linux machine.</A>
<LI><A HREF="#Heading8">Listing Process Information</A>
<LI><A HREF="#Heading9">Listing 58.4. The directories under /proc/processID.</A>
<LI><A HREF="#Heading10">Listing 58.5. Listing the working environment for a process.</A>
<LI><A HREF="#Heading11">Showing Memory Maps for Processes</A>
<LI><A HREF="#Heading12">Listing 58.6. Showing memory maps.</A>
<LI><A HREF="#Heading13">Listing 58.7. Memory information.</A>
<LI><A HREF="#Heading14">Information on Disk Usage</A>
<LI><A HREF="#Heading15">Listing 58.8. Statistics on your system.</A>
<LI><A HREF="#Heading16">Determining System Specifications</A>
<LI><A HREF="#Heading17">Listing 58.9. Showing memory maps as an HTML file.</A>
<LI><A HREF="#Heading18">Listing 58.10. An HTML file showing memory maps as an HTML
file.</A>
<LI><A HREF="#Heading19">Summary</A>
</UL>
</UL>
</UL>
<P>
<HR SIZE="4">
<H2 ALIGN="CENTER"><A NAME="Heading1<FONT COLOR="#000077">- 58 -</FONT></H2>
<H2 ALIGN="CENTER"><A NAME="Heading2<FONT COLOR="#000077">The Pseudo File System</FONT></H2>
<P><I>by Kamran Husain</I></P>
<P>IN THIS CHAPTER</P>
<UL>
<LI>Looking at Interrupts
<P>
<LI>Listing the IO Ports
<P>
<LI>Listing Process Information
<P>
<LI>Showing Memory Maps for Processes
<P>
<LI>Information on Disk Usage
<P>
<LI>Determining System Specifications
</UL>
<P>Linux supports the pseudo file system interface to the internal data structures
for the kernel. This is your private view of parameters used by the Linux kernel.
Using this file system, you can look at the internal data structures for processes
and some internal kernel data structures as well. You can get all this information
in a "read-only" directory called the <TT>/proc</TT> directory. You can
access a more detailed man page for this information via the following command:<FONT
COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">$ man 5 proc
</FONT></PRE>
<P>(Don't use <TT>man proc</TT> because that will give you the man (n) pages for
Tcl's proc.) The man page describes the formats for all the outputs in the system.
This section will introduce you to some of the more common useful features of <TT>/proc</TT>.
We'll cover how to use these numbers in this chapter.</P>
<P>Let's look at a typical listing of the <TT>/proc</TT> directory, as shown in Listing
58.1.
<H3 ALIGN="CENTER"><A NAME="Heading3<FONT COLOR="#000077">Listing 58.1. A typical
listing of /proc.</FONT><FONT COLOR="#0066FF"></FONT></H3>
<PRE><FONT COLOR="#0066FF">$ ls -l /proc
total 0
dr-xr-xr-x 3 root root 0 Oct 18 08:30 1
dr-xr-xr-x 3 root root 0 Oct 18 08:30 13
dr-xr-xr-x 3 root root 0 Oct 18 08:30 2
dr-xr-xr-x 3 root root 0 Oct 18 08:30 3
dr-xr-xr-x 3 khusain users 0 Oct 18 08:30 3057
dr-xr-xr-x 3 root nogroup 0 Oct 18 08:30 3963
dr-xr-xr-x 3 root root 0 Oct 18 08:30 4
dr-xr-xr-x 3 khusain users 0 Oct 18 08:30 4102
dr-xr-xr-x 3 root users 0 Oct 18 08:30 4103
dr-xr-xr-x 3 khusain users 0 Oct 18 08:30 4105
dr-xr-xr-x 3 root users 0 Oct 18 08:30 4106
dr-xr-xr-x 3 root users 0 Oct 18 08:30 4107
dr-xr-xr-x 3 khusain users 0 Oct 18 08:30 4108
dr-xr-xr-x 3 khusain users 0 Oct 18 08:30 4109
dr-xr-xr-x 3 khusain users 0 Oct 18 08:30 4110
dr-xr-xr-x 3 khusain users 0 Oct 18 08:30 4111
dr-xr-xr-x 3 khusain users 0 Oct 18 08:30 4125
dr-xr-xr-x 3 root root 0 Oct 18 08:30 43
dr-xr-xr-x 3 root root 0 Oct 18 08:30 5
dr-xr-xr-x 3 root root 0 Oct 18 08:30 5058
dr-xr-xr-x 3 khusain users 0 Oct 18 08:30 5059
dr-xr-xr-x 3 khusain users 0 Oct 18 08:30 5437
dr-xr-xr-x 3 khusain users 0 Oct 18 08:30 5448
dr-xr-xr-x 3 khusain users 0 Oct 18 08:30 5450
dr-xr-xr-x 3 khusain users 0 Oct 18 08:30 5454
dr-xr-xr-x 3 khusain users 0 Oct 18 08:30 5555
dr-xr-xr-x 3 root root 0 Oct 18 08:30 6
dr-xr-xr-x 3 root root 0 Oct 18 08:30 62
dr-xr-xr-x 3 root root 0 Oct 18 08:30 64
dr-xr-xr-x 3 bin root 0 Oct 18 08:30 66
dr-xr-xr-x 3 root root 0 Oct 18 08:30 68
dr-xr-xr-x 3 root root 0 Oct 18 08:30 7
dr-xr-xr-x 3 root root 0 Oct 18 08:30 70
dr-xr-xr-x 3 root root 0 Oct 18 08:30 708
dr-xr-xr-x 3 root root 0 Oct 18 08:30 72
dr-xr-xr-x 3 root root 0 Oct 18 08:30 75
dr-xr-xr-x 3 khusain users 0 Oct 18 08:30 84
dr-xr-xr-x 3 root root 0 Oct 18 08:30 85
dr-xr-xr-x 3 root root 0 Oct 18 08:30 86
dr-xr-xr-x 3 root root 0 Oct 18 08:30 87
dr-xr-xr-x 3 root root 0 Oct 18 08:30 88
dr-xr-xr-x 3 root root 0 Oct 18 08:30 89
-r--r--r-- 1 root root 0 Oct 18 08:30 cmdline
-r--r--r-- 1 root root 0 Oct 18 08:30 cpuinfo
-r--r--r-- 1 root root 0 Oct 18 08:30 devices
-r--r--r-- 1 root root 0 Oct 18 08:30 dma
-r--r--r-- 1 root root 0 Oct 18 08:30 filesystems
-r--r--r-- 1 root root 0 Oct 18 08:30 interrupts
-r--r--r-- 1 root root 0 Oct 18 08:30 ioports
-r-------- 1 root root 33558528 Oct 18 08:30 kcore
-r-------- 1 root root 0 Sep 26 20:51 kmsg
-r--r--r-- 1 root root 0 Oct 18 08:30 ksyms
-r--r--r-- 1 root root 0 Oct 18 07:58 loadavg
-r--r--r-- 1 root root 0 Oct 18 08:30 locks
-r--r--r-- 1 root root 0 Oct 18 08:30 meminfo
-r--r--r-- 1 root root 0 Oct 18 08:30 modules
-r--r--r-- 1 root root 0 Oct 18 08:30 mounts
dr-xr-xr-x 2 root root 0 Oct 18 08:30 net
-r--r--r-- 1 root root 0 Oct 18 08:30 pci
dr-xr-xr-x 2 root root 0 Oct 18 08:30 scsi
lrwxrwxrwx 1 root root 64 Oct 18 08:30 self -> 5555
-r--r--r-- 1 root root 0 Oct 18 08:30 stat
dr-xr-xr-x 5 root root 0 Oct 18 08:30 sys
-r--r--r-- 1 root root 0 Oct 18 08:30 uptime
-r--r--r-- 1 root root 0 Oct 18 08:30 version
</FONT></PRE>
<P>Several points of interest can be seen in this listing. First of all, you see
numbered directories. These numbers correspond to process IDs for processes that
are running on the system when you issue the command. Naturally, your display will
be different than that shown in Listing 58.1, because process IDs rarely match on
different systems. The second thing to note is that the file sizes are zero. This
includes all the subdirectories in <TT>/proc</TT>. Links, of course, have sizes.</P>
<P>Each of these subdirectories is a "window" into the kernel. On other
UNIX-like systems, you have to be able to read <TT>/dev/kmem</TT> and figure out
what your kernel is up to. On those UNIX systems that support <TT>/proc</TT> (almost
all newer ones do), including Linux, you can look at the information conveniently.
There is one catch to this convenience, though. In most cases, <TT>/dev/kmem</TT>
is readable only by the root, whereas the <TT>/proc</TT> tree is readable by all.</P>
<P>Let's look at some of the input you can get from these files.
<H3 ALIGN="CENTER"><A NAME="Heading4<FONT COLOR="#000077">Looking at Interrupts</FONT></H3>
<P>The <TT>/proc/interrupts</TT> directory provides information about the currently
used interrupts your Linux kernel is using. Listing 58.2 shows some of the interrupts
on my system.
<H3 ALIGN="CENTER"><A NAME="Heading5<FONT COLOR="#000077">Listing 58.2. Show
the interrupts in the system.</FONT><FONT COLOR="#0066FF"></FONT></H3>
<PRE><FONT COLOR="#0066FF">$ cat /proc/interrupts
0: 185693319 timer
1: 751422 keyboard
2: 0 cascade
4: 891729 + serial
9: 282710 NE2000
10: 375073 NE2000
13: 0 math error
14: 2166148 + ide0
</FONT></PRE>
<P>The numbers for the items you see on your screen will most certainly be different.
The format of this output is straightforward. The left column is the interrupt number.
The number of hits is shown in the middle column, followed by the name of the driver
being used.
<H3 ALIGN="CENTER"><A NAME="Heading6<FONT COLOR="#000077">Listing the IO Ports</FONT></H3>
<P>The <TT>/proc/ioports</TT> directory lists all the used IO ports on your Linux
machine.</P>
<P>The output from <TT>/proc/ioports</TT>, coupled with the output from <TT>/proc/interrupts</TT>,
helps you a great deal when you are trying to debug something. Here's an example
I ran into while setting up a firewall recently. I had two NE2000 Ethernet cards
in the system using interrupts 9 and 10, as shown in Listing 58.2. When the cards
were first installed together, neither card worked. Individually, they worked fine.
There was an obvious port conflict. I installed both cards and booted the Linux system.
To see which ports it was using, I looked at <TT>/proc/ioports</TT> and saw that
both cards were defaulting to the same port. After a CMOS setup, the Linux machine
was up in a jiffy. The output from the <TT>/proc/ioports</TT> now looks as shown
in Listing 58.3.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -