⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch58.htm

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTM
📖 第 1 页 / 共 2 页
字号:


<H3 ALIGN="CENTER"><A NAME="Heading7<FONT COLOR="#000077">Listing 58.3. The



/proc/ioports listing of IO ports on a Linux machine.</FONT><FONT COLOR="#0066FF"></FONT></H3>



<PRE><FONT COLOR="#0066FF">$ cat /proc/ioports



0000-001f : dma1



0020-003f : pic1



0040-005f : timer



0060-006f : keyboard



0080-009f : dma page reg



00a0-00bf : pic2



00c0-00df : dma2



00f0-00ff : npu



01f0-01f7 : ide0



0260-0263 : sbpcd



02f8-02ff : serial(auto)



0300-031f : NE2000



0340-035f : NE2000



0378-037f : lp



03c0-03df : vga+



03e8-03ef : serial(auto)



03f0-03f5 : floppy



03f6-03f6 : ide0



03f7-03f7 : floppy DIR



03f8-03ff : serial(auto)



</FONT></PRE>



<H3 ALIGN="CENTER"><A NAME="Heading8<FONT COLOR="#000077">Listing Process Information</FONT></H3>



<P>There is a large amount of information about a process. Let's look at the information



about the process ID 5454 by looking in the <TT>/proc/5454</TT> directory. The output



is shown in Listing 58.4.



<H3 ALIGN="CENTER"><A NAME="Heading9<FONT COLOR="#000077">Listing 58.4. The



directories under /proc/processID.</FONT><FONT COLOR="#0066FF"></FONT></H3>



<PRE><FONT COLOR="#0066FF">$ ls -l /proc/5454



total 0



-r--r--r--   1 khusain  users           0 Oct 18 08:52 cmdline



lrwx------   1 khusain  users          64 Oct 18 08:51 cwd -&gt; [0302]:132748



-r--------   1 khusain  users           0 Oct 18 08:52 environ



lrwx------   1 khusain  users          64 Oct 18 08:52 exe -&gt; [0302]:22524



dr-x------   1 khusain  users           0 Oct 18 08:52 fd



pr--r--r--   1 khusain  users           0 Oct 18 08:52 maps



-rw------    1 khusain  users           0 Oct 18 08:52 mem



lrwx------   1 khusain  users          64 Oct 18 08:52 root -&gt; [0302]:2



-r--r--r--   1 khusain  users           0 Oct 18 08:52 stat



-r--r--r--   1 khusain  users           0 Oct 18 08:52 statm



-r--r--r--   1 khusain  users           0 Oct 18 08:52 status



</FONT></PRE>



<P>The command line that invoked the file is shown in <TT>/proc/</TT>ID<TT>/cmdline</TT>.<TT>



</TT>Replace the ID with the process ID you are interested in. Get the ID from the



output <TT>ps ax</TT> command. All the arguments are strings separated by zero bytes.



These bytes have to be translated to new lines for each argument to be shown separately.



The way to see the output is to use this command:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">$ cat /proc/5454/cmdline | tr &quot;\000&quot; &quot;\n&quot;



vi



myfiles.txt$



</FONT></PRE>



<P>The working environment for a process can be seen via the <TT>/proc/environ</TT>



directory. As with the cmdline output, all zeros have to be translated to <TT>&quot;\n&quot;</TT>



for the output to be meaningful. If you do not do so, all the environment strings



will be gelled together in one long string on the output. The command will look a



bit like the one shown in Listing 58.5. (Your output will look different than what's



shown here.)



<H3 ALIGN="CENTER"><A NAME="Heading10<FONT COLOR="#000077">Listing 58.5. Listing



the working environment for a process.</FONT><FONT COLOR="#0066FF"></FONT></H3>



<PRE><FONT COLOR="#0066FF">$ cat /proc/5454/environ | tr &quot;\000&quot; &quot;\n&quot;



LESSOPEN=|lesspipe.sh %s



ignoreeof=10



HOSTNAME=www.ikra.com



LOGNAME=khusain



MINICOM=-c on



MAIL=/var/spool/mail/khusain



TERMCAP=vs|xterm|vs100|xterm terminal emulator (X Window System):am:bs:km:co#80:li#24:ct=\E[3k:ue=\E[m:is=\E[m\E[?1l\E&gt;:rs=\E[m



\E[?1l\E&gt;:eA=\E)0:as=^N:ae=^O:ac=aaffggjjkkllmmnnooqqssttuuvvwwxx:kI=\



E[2~:kD=:kP=\E[5~:kN=\E[6~:k1=\E[11~:k2=\E[12~:k3=\E[13~:k4=\E[14~:k5



=\E[15~:k6=\E[17~:k7=\E[18~:k8=\E[19~:k9=\E[20~:k0=\E[21~:F1=\E[23~:F2



=\E[24~:kh=\E[H:kH=\EOw:ks=:ke=:te=\E[2J\E[?47l\E8:ti=\E7\E[?47h:ms:pt



:xn:xo:it#8:RA=\E[?7l:SA=\E?7h:bl=^G:cr=^M:ta=^I:cm=\E[%i%d;%dH:le=^H:



up=\E[A:do=\E[B:nd=\E[C:LE=\E[%dD:RI=\E[%dC:UP=\E[%dA:DO=\E[%dB:ho=\E[



H:cl=\E[H\E[2J:ce=\E[K:cb=\E[1K:cd=\E[J:sf=\ED:sr=\EM:st=\EH:cs=\E[%i%



d;%dr:sc=\E7:rc=\E8:ic=\E[@:IC=\E[%d@:al=\E[L:AL=\E[%dL:dc=\E[P:DC=\E[



%dP:dl=\E[M:DL=\E[%dM:so=\E[7m:se=\E[m:us=\E[4m:mb=\E[5m:mh=\E[2m:md=\



E[1m:mr=\E[7m:me=\E[m:kb=:ku=\E[A:kd=\E[B:kr=\E[C:kl=\E[D:



TERM=xterm



HOSTTYPE=i386



PATH=/usr/local/bin:/bin:/usr/bin:/usr/X11/bin:/usr/games:.



HOME=/home/khusain



SHELL=/bin/bash



LS_OPTIONS=--8bit --color=tty -F -b -T 0



MANPATH=/usr/local/man:/usr/man/preformat:/usr/man:/usr/X11/man:/usr/openwin/man



LESS=-MM



DISPLAY=:0.0



OSTYPE=Linux



WINDOWID=8388621



OPENWINHOME=/usr/openwin



SHLVL=3



LS_COLORS=no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:



d=40;33;01:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01;32:*.btm=01;32:*.at=01;32:



*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;3:*.zip=01;31:*.z=01;



31:*.Z=01;31:*.gz=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01;35:*.xbm=01;35:*.xpm=



01;35:*.tif=01;35:=/usr/bin/vi$



</FONT></PRE>



<H3 ALIGN="CENTER"><A NAME="Heading11<FONT COLOR="#000077">Showing Memory Maps



for Processes</FONT></H3>



<P>Other good information about the process is where the sections of the process



are loaded in memory. This information is found in the <TT>/proc/mmaps</TT> directory.



Examining the directory for a process whose ID is 5454 gives the output shown in



Listing 58.6.



<H3 ALIGN="CENTER"><A NAME="Heading12<FONT COLOR="#000077">Listing 58.6. Showing



memory maps.</FONT><FONT COLOR="#0066FF"></FONT></H3>



<PRE><FONT COLOR="#0066FF">$ cat /proc/5454/maps



08048000-0805f000 r-xp 00000000 03:02 22524



0805f000-08061000 rw-p 00016000 03:02 22524



08061000-0806c000 rwxp 00000000 00:00 0



40000000-40005000 rwxp 00000000 03:02 46931



40005000-40006000 rw-p 00004000 03:02 46931



40006000-40007000 rw-p 00000000 00:00 0



40009000-4000b000 r-xp 00000000 03:02 87901



4000b000-4000c000 rw-p 00001000 03:02 87901



4000c000-40085000 r-xp 00000000 03:02 87903



40085000-4008b000 rw-p 00078000 03:02 87903



4008b000-400bd000 rw-p 00000000 00:00 0



bfffe000-c0000000 rwxp fffff000 00:00 0



</FONT></PRE>



<P>This is the format of each line in the output:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">address permissions offset major:minor inode



</FONT></PRE>



<P>The permissions are the same as those for a process--read, write, and execute.



The <TT>p</TT> stands for private section. If a section is shared, you should have



<TT>s</TT>. The offset is the offset within the file. The major and minor numbers



correspond to device names for this process, and the inode is the one corresponding



to the page.</P>



<P>One of the most common things you are likely to be concerned with while using



Linux is how much memory you're chewing up at the moment. To get a snapshot of the



current memory usage, you can use the <TT>free</TT> command or look at <TT>/proc/meminfo</TT>.



The output is simple and easy to understand, as shown in Listing 58.7.



<H3 ALIGN="CENTER"><A NAME="Heading13<FONT COLOR="#000077">Listing 58.7. Memory



information.</FONT><FONT COLOR="#0066FF"></FONT></H3>



<PRE><FONT COLOR="#0066FF">$ cat /proc/meminfo







        total:    used:    free:  shared: buffers:  cached:



Mem:  31670272 30707712   962560 15962112  1359872 13742080



Swap: 35090432   307200 34783232



MemTotal:     30928 kB



MemFree:        940 kB



MemShared:    15588 kB



Buffers:       1328 kB



Cached:       13420 kB



SwapTotal:    34268 kB



SwapFree:     33968 kB



</FONT></PRE>



<H3 ALIGN="CENTER"><A NAME="Heading14<FONT COLOR="#000077">Information on Disk



Usage</FONT></H3>



<P>Other interesting statistics for disk usage are available for those whose really



need to know how their system is working. Examining these statistics to see how your



system is fairing is a fairly reasonable way to look at the behavior of the system.



Look at the output from <TT>/proc/stat</TT> shown in Listing 58.8.



<H3 ALIGN="CENTER"><A NAME="Heading15<FONT COLOR="#000077">Listing 58.8. Statistics



on your system.</FONT><FONT COLOR="#0066FF"></FONT></H3>



<PRE><FONT COLOR="#0066FF">$ cat /proc/stat



cpu  7827918 0 697778 186968393



disk 505252 1 0 0



disk_rio 209050 1 0 0



disk_wio 296202 0 0 0



disk_rblk 525758 2 0 0



disk_wblk 592830 0 0 0



page 533561 699895



swap 17961 75



intr 200154670 195494089 644075 0 0 1201601 0 155 0 0 283570 240158



0 0 0 2291022 0



ctxt 11001290



btime 847886750



processes 23920



</FONT></PRE>



<P>The only time I really have used this output was to see how a very large sort



program was hitting the page count. The pages being swapped in and out of memory



are counted off in the display. The disk light never seemed to go off. The number



of page swaps jumped up a lot every time I ran the program when I had a mere 8MB



of RAM. After an upgrade to 32MB of RAM, and when I was not running the program in



an xterm, the number of pages did not jump up so dramatically. The CPU entry lists



the time spent in 1/100ths of seconds in user mode, system mode idling, and uptime.



The meanings of the cryptic numbers in the rest of the fields are listed in the man



pages.</P>



<P>Another item to look at is the <TT>/proc/uptime</TT> numbers, which list the total



number of seconds spent processing and those spent in idle state. These numbers might



not be as precise as you want. You should write your own benchmarking routines if



you want precise numbers. The output shown here from <TT>/proc/uptime</TT> is an



example:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">$ cat /proc/uptime



1954987.45 1869728.55



</FONT></PRE>



<P>The second item in the output is the idle time for the CPU. Note how the idle



time is almost 100 times the same number as the fourth number for the idle time in



the CPU field from the <TT>/proc/stat</TT> output. They don't match exactly, because



the time required between the typing of these two commands (or to collect this information)



is not zero.



<H3 ALIGN="CENTER"><A NAME="Heading16<FONT COLOR="#000077">Determining System



Specifications</FONT></H3>



<P>Through some judicious use of the information in <TT>/proc</TT>, a process can



determine the specifications for the curre







</td>
</tr>
</table>

<!-- begin footer information -->



</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -