转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 软件使用 >> 系统软件 >> 正文
Exploring /proc         

Exploring /proc

作者:闵涛 文章来源:闵涛的学习笔记 点击数:1604 更新时间:2009/4/25 0:44:45
Exploring /proc
By Trevor Warren <trevorwarren@yahoo.com>
 Posted: ( 2000-12-12 10:03:00 EST by  )
 The Proc psuedo file system is a real time, memory resident file system
 that tracks the processes running on your machine and the state of your
 system. Read on to learn how to get the most out of the /proc file system.
 
The most striking factor about the /proc file system is the fact that the
file system doesn''''t exist on any particular media. The /proc File System
is a pseudo file system residing in the virtual memory and
maintains highly dynamic data on the state of your operating system. Most
of the information in the /proc file system is updated to match the
current state of the operating system. The contents of the /proc file
system can be read by anyone who has the requisite permissions. However,
certain parts of the /proc file system can be read only by the owner of
the process and of course root. The contents of the /proc filesystem are
used by many utilities which grab the data from the particular /proc
directory and display it.
Under Linux, we have utilities like lscpi, scanpci and pnpdump which help
us detect the various PCI, ISA hardware chipsets and help us make the best
choices as far as the io, dma and irq values are concerned. Similarly by
looking at the values of the various parameters in the /proc file system,
one can determine a lot about the current state of the kernel and the
processes under way. For example, we have the dmesg command.
bash# dmesg
Dmesg helps us determine the devices that have been detected and
initialized by the Linux kernel. We have utilities like "ps" and "top"
which give an accurate snapshot about the status of the processes running
on the machine and a list of awake and sleeping processes currently
running on the machine. Have you ever wondered where exactly the
information dished out to you by the "ps" and the "top" process comes
from? The information for these processes come from the /proc file system
which is updated on the fly as changes take place in the processes.
Lets take a look at a snapshot of the directory listing of the root (/)
directory of a Linux machine.
drwxr-xr-x 14 root root 291 Oct 25 18:47 opt
dr-xr-xr-x 86 root root 0 Nov 30 2000 proc <--
drwx--x--x 16 root root 841 Nov 20 00:10 root
drwxr-xr-x 5 root root 4627 Oct 15 11:42 sbin
Since the /proc file system is a virtual file system and resides in
memory, a new /proc file system is created every time your Linux machine
reboots. Take a look at the snapshot of the root directory shown above.
The size of the proc directory is 0 and the last time of modification is
the current date.
Using the /proc/sys file system to parse kernel parameters.
Another very important part of the /proc file system is the /proc/sys
directory. Making changes in this directory enables you to make real time
changes to certain kernel parameters. One fine example that can illustrate
this is as follows.
 /proc/sys/net/ipv4/ip_forward
 
The above file ip_forward has a default value of "0" which you can see
when you cat the contents of this file. This means that IP forwarding by
this machine isn''''t allowed by the kernel. But this configuration can be
changed in real time by just changing the value stored in this file from
"0" to "1". Thus we have enabled IP forwarding on our Linux machine.
 
Contents of the /proc File System
The output of the directory listing of the /proc directory is as follows.
The actual listing was really lengthy. What''''s given below is a much
shorter version.
 
1 114 1210 1211 1212 1227 133 137 148 160 161 163 167 168 169
170 171 172 173 174 186 190 193 194 195 203 206 207 208 209
210 211 220 221 222 223 224 225 226 227 229 230 234 246 253 279
296 3 4 5 500 501 6 667 668 669 683 684 685 7 711 712 713 737 763
764 765 766 773 774 775 782 79 88 92 asound bus cmdline config.gz
cpuinfo devices dma fb filesystems fs ide interrupts ioports
kcore kcore_elf kmsg ksyms loadavg locks lvm mdstat meminfo
memstat misc modules mounts net partitions pci rtc scsi self
slabinfo stat swaps sys tty uptime version
Every number and word that you see in the above snapshot are the contents of
the /proc directory. Lets learn a little more about the contents of the
directories with the numerical naming scheme.
The numerical named directories
 1 114 1210 1211 1212 1227 133 137 148 160 161 163 167 168 169
170 171 172 173 174 186 190 193 194 195 203 206 207 208 209
210 211 220 221 222 223 224 225 226 227 229 230 234 246 253 279
296 3 4 5 500 501 6 667 668 669 683 684 685 7 711 712 713 737 763
764 765 766 773 774 775 782 79 88 92
The various directories that you see out here are the processes that were
running on our machine at the instant we took a snapshot of the /proc
file system. Let''''s look at the contents of one of these directories.
freeos:~ # cd /proc
freeos:/proc # ls -la 114
total 0
dr-xr-xr-x 3 named named 0 Nov 30 12:20 .
dr-xr-xr-x 89 root root 0 Nov 30 2000 ..
-r--r--r-- 1 root root 0 Nov 30 12:20 cmdline
lrwx------ 1 root root 0 Nov 30 12:20 cwd -> /var/named
-r-------- 1 root root 0 Nov 30 12:20 environ
lrwx------ 1 root root 0 Nov 30 12:20 exe -> /usr/sbin/named
dr-x------ 2 root root 0 Nov 30 12:20 fd
pr--r--r-- 1 root root 0 Nov 30 12:20 maps
-rw------- 1 root root 0 Nov 30 12:20 mem
lrwx------ 1 root root 0 Nov 30 12:20 root -> /
-r--r--r-- 1 root root 0 Nov 30 12:20 stat
-r--r--r-- 1 root root 0 Nov 30 12:20 statm
-r--r--r-- 1 root root 0 Nov 30 12:20 status
Before executing this command you need to log in as root because the
various processes running on the system may be owned by various other
users. As usual you have access only to the processes that you have
started. After having logged in as root just execute the above command for
any of the directories and compare the output to what is listed above.
Did you notice any similarity in the output you got and the one listed
above? Yes, the contents of all the directories are the same irrespective
of the directory you choose to view as these directories contain the
various parameters and the status of the process whose PID is the name of
the current directory that you are in. The values of the various
parameters and status information would of course vary from process to
process.
Look at the first line of the output as viewed above.
 -r--r--r-- 1 root root 0 Nov30 12:20 cmdline
"cmdline", this file contains the whole command line used to invoke the
process. The contents of this file are the command line arguments with all
the parameters that one has passed to start the particular process. All
the information contained in the file is without any formatting and any
space between the command line arguments and various arguments.
 lrwx------ 1 root root 0 Nov 30 12:20 cwd -> /var/named
"cwd", as is visible from above this is a symbolic link to the current
working directory of that particular process.
 -r-------- 1 root root 0 Nov 30 12:20 environ
"environ" contains all the environment variables defined for this
particular process in the form VARIABLE=value. As with cmdline, all the
information contained in the file is without any formatting or space
between the command line a

[1] [2]  下一页


[办公软件]在sybase中插入图片、PDF、文本文件  [办公软件]安装Sybase ASE
[办公软件]linux指令大全(完整篇)  [办公软件]Linux新手入门常用命令大全
[办公软件]在RedHat Linux 9里安装gaim0.80  [办公软件]浅谈Linux 下Java 1.5 汉字方块问题解决方法
[办公软件]Linux程序员必读:中文化与GB18030标准  [办公软件]linux指令大全
[办公软件]制作Linux启动盘的四种方法  [办公软件]Linux文件系统的反删除方法
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · 办公软件  · 系统软件
    · 常用软件  · 聊天工具
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台