What are the functions of subfiles or subfolders in the Linux proc directory?

王林
Release: 2023-05-13 10:49:12
forward
1400 people have browsed it

1. Linux /proc Directory Introduction
The Linux kernel provides a mechanism to access the internal data structures of the kernel and change kernel settings at runtime through the /proc file system. The proc file system is a pseudo file system that only exists in memory and does not occupy external memory space. It provides an interface for accessing system kernel data in the form of a file system.
Users and applications can obtain system information through proc and change certain parameters of the kernel. Since system information, such as processes, changes dynamically, when a user or application reads a proc file, the proc file system dynamically reads the required information from the system kernel and submits it. Not all of the files or subfolders listed below may exist on your system, depending on your kernel configuration and loaded modules. In addition, there are three very important directories under /proc: net, scsi and sys. The sys directory is writable and can be used to access or modify kernel parameters, while net and scsi depend on the kernel configuration. For example, if the system does not support scsi, the scsi directory does not exist.
In addition to the ones introduced above, there are also some directories named with numbers, which are process directories. Each process currently running in the system has a corresponding directory under /proc, with the pid number of the process as the directory name. They are the interfaces for reading process information. The self directory is the information interface for reading the process itself, which is a link.
2. The role of sub-files or sub-folders in the /proc directory
/proc/buddyinfo How many blocks are available for each order in each memory area is related to the memory fragmentation problem
/proc/cmdline Parameter information passed to the kernel at startup
/proc/cpuinfo cpu information
/proc/crypto All installed encryption passwords and details used by the kernel
/proc/devices Already Loaded devices and categories
/proc/dma List of isa dma channels registered for use
/proc/execdomains Execution domains currently supported by the Linux kernel
/proc/fb List of frame buffer devices, including number and control Its driver
/proc/filesystems The file system types currently supported by the kernel
/proc/interrupts The number of interrupts per irq in the x86 architecture
/proc/iomem The number of each physical device currently in system memory Mapping
/proc/ioports The registered port range used for the input and output of a device
/proc/kcore represents the physical memory of the system and is stored in core file format. The number of bytes displayed is equal to the ram size plus Up 4kb
/proc/kmsg records the information generated by the kernel, which can be processed through /sbin/klogd or /bin/dmesg
/proc/loadavg The load status based on the status of cpu and io in the past period of time , related to the uptime command
/proc/locks Kernel locked file list
/proc/mdstat Multiple hard drives, raid configuration information (md=multiple disks)
/proc/meminfo Ram usage related information
/proc/misc Drivers registered on other major devices (device number 10)
/proc/modules List of all modules loaded into the kernel
/proc/mounts All mounts used in the system
/proc/mtrr Memory type range registers (mtrrs) used by the system
/proc/partitions Block allocation information in the partition
/proc/pci PCI device list in the system
/proc/slabinfo System All active slab cache information
/proc/stat All cpu activity information
/proc/sysrq-trigger When using the echo command to write this file, the remote root user can execute most system request key commands. Just like executing in local terminal. To write to this file, /proc/sys/kernel/sysrq must not be set to 0. This file is also unreadable by root
/proc/uptime How long the system has been running
/proc/swaps Swap space usage
/proc/version Linux kernel version and gcc version
/proc /bus system bus (bus) information, such as pci/usb, etc.
/proc/driver driver information
/proc/fs file system information
/proc/ide ide device information
/proc/irq Interrupt request device information
/proc/net Network card device information
/proc/scsi scsi device information
/proc/tty tty device information
/proc/net/dev Display network adapter and statistical information
/proc/vmstat Virtual memory statistics
/proc/vmcore Memory image when kernel panics
/proc/diskstats Obtain disk information
/proc/schedstat Kernel scheduler statistics
/ proc/zoneinfo displays the statistical information of the memory space, which is useful for analyzing virtual memory behavior
The following is the information of process n in the /proc directory
/proc/n Process information with pid n
/proc/n /cmdline Process startup command
/proc/n/cwd Link to the current working directory of the process
/proc/n/environ Process environment variable list
/proc/n/exe Link to the execution command file of the process
/proc/n/fd contains all file descriptors related to the process
/proc/n/maps Memory mapping information related to the process
/proc/n/mem refers to the memory held by the process, Unreadable
/proc/n/root Link to the root directory of the process
/proc/n/stat The status of the process
/proc/n/statm The status of the memory used by the process
/proc/ n/status process status information, more readable than stat/statm
/proc/self links to the currently running process
3. Practical operation example
1. Column Export all files under /proc/

yafang@qa:~$ ls /proc/
1      16819  21242  2180   2494  8768         interrupts    partitions
116    16820  21244  2181   2524  885          iomem         sched_debug
11740  17901  21245  21810  2525  acpi         ioports       scsi
11742  17903  21247  21812  3     asound       irq           self
11743  17904  2131   21813  39    buddyinfo    kallsyms      slabinfo
13452  18362  21319  21923  4     bus          kcore         stat
13454  18364  2132   2193   41    cgroups      key-users     swaps
13455  18365  2139   21933  42    cmdline      kmsg          sys
149    19451  2142   2209   5     cpuinfo      kpagecount    sysrq-trigger
150    19453  21572  2212   5330  crypto       kpageflags    sysvipc
151    19454  21574  2219   596   devices      loadavg       timer_list
152    2      21575  2243   597   diskstats    locks         timer_stats
15771  2083   2158   2260   6     dma          meminfo       tty
15773  2092   21625  2261   617   driver       misc          uptime
15774  2101   21627  2262   619   execdomains  modules       version
16232  21112  21628  2263   7     fb           mounts        vmallocinfo
16234  21115  2165   2264   804   filesystems  mtrr          vmstat
16235  21116  2167   2265   8765  fs           net           zoneinfo
16811  2112   2177   2338   8767  ide          pagetypeinfo
Copy after login

2. View system information and kernel parameters

yafang@qa:~$ ls /proc/sys
debug  dev  fs  kernel  net  vm[code]
Copy after login

3. 查看网卡设备信息

[code]yafang@qa:~$ ls /proc/net
anycast6   ip6_flowlabel  netfilter  raw6       sockstat6     udplite
arp        ip6_mr_cache   netlink    route      softnet_stat  udplite6
dev        ip6_mr_vif     netstat    rt6_stats  stat          unix
dev_mcast  ip_mr_cache    packet     rt_acct    tcp           vlan
dev_snmp6  ip_mr_vif      protocols  rt_cache   tcp6          wireless
if_inet6   ipv6_route     psched     snmp       tr_rif
igmp       mcfilter       ptype      snmp6      udp
igmp6      mcfilter6      raw        sockstat   udp6
Copy after login

4. 查看scsi设备信息

yafang@qa:~$ ls /proc/scsi
device_info  scsi
Copy after login

5. 查看所有加载到内核的模块列表

root@bdsp-a-2-1-2:~# cat /proc/modules
bdspboard 8486 2 dspcontrol, live 0xe134c000
dspcontrol 9575 1 clkmon, live 0xe135b000
clkmon 6765 1 - live 0xe136c000
diagint 6635 1 - live 0xe1379000
bdsprio 10775 2 srioif,tsi577, live 0xe9389000
tsi577 17998 1 srioif, live 0xe939e000
srioif 7329 0 - live 0xe93b2000
linux_kernel_bde 54666 1 linux_user_bde, live 0xf1417000 (p)
linux_user_bde 17849 0 - live 0xf1427000 (p)
root@bdsp-a-2-1-2:~#
Copy after login

6. 查看已经加载的设备并分类

root@bcnmb-a:~# cat /proc/devicescharacter 
devices:  1 mem  2 pty  3 ttyp  4 /dev/vc/0  4 tty  4 ttys  5 /dev/tty  5 /dev/console  5 /dev/ptmx  7 vcs 10 misc 13 input 89 i2c 90 mtd116 linux-user-bde2117 linux-kernel-bde2126 linux-user-bde127 linux-kernel-bde128 ptm136 pts180 usb189 usb_device245 ext_alarm251 ipmidev252 usb_endpoint253 usbmon254 rtcblock devices:  1 ramdisk  8 sd 31 mtdblock 65 sd 66 sd 67 sd 68 sd 69 sd 70 sd 71 sd128 sd129 sd130 sd131 sd132 sd133 sd134 sd135 sd
root@bcnmb-a:~#
Copy after login

7. 查看分区中的块分配信息

root@bdsp-a-2-1-2:~# cat /proc/partitions
major minor  #blocks  name
  31        0        512 mtdblock0
  31        1        512 mtdblock1
  31        2     123904 mtdblock2
  31        3       4096 mtdblock3
  31        4       1024 mtdblock4
  31        5       1024 mtdblock5
  31        6        512 mtdblock6
  31        7        512 mtdblock7
  31        8     123904 mtdblock8
  31        9       4096 mtdblock9
  31       10       1024 mtdblock10
  31       11       1024 mtdblock11
  31       12    1048576 mtdblock12
root@bdsp-a-2-1-2:~#
Copy after login

8. 查看linux内核版本和gcc版本

root@bdsp-a-2-1-2:~# cat /proc/version
linux version 2.6.34.6-wr4.0.0.0_standard (satomi@charliebrown) (gcc version 4.4.1 (wind river linux sourcery g++ 4.4-291) ) #1 smp preempt fri nov 26 16:07:47 cst 2010
root@bdsp-a-2-1-2:~#
Copy after login

9. /proc/sys/fs/file-max
该文件指定了可以分配的文件句柄的最大数目。如果用户得到的错误消息声明由于打开文件数已经达到了最大值,从而他们不能打开更多文件,则可能需要增加该值。可将这个值设置成有任意多个文件,并且能通过将一个新数字值写入该文件来更改该值。默认设置时4096。
改变内核的参数,用vi编辑或echo参数重定向到文件中。

# cat /proc/sys/fs/file-max
4096
# echo 8192 > /proc/sys/fs/file-max
# cat /proc/sys/fs/file-max
8192
Copy after login

如果优化了参数,则可以把它们写成添加到文件rc.local中,使它在系统启动时自动完成修改。

其它例子:

1:[root@gechong proc]# more /proc/cmdline
显示了内核启动的命令行
2:[root@gechong proc]# cat /proc/cpuinfo
显示了cpu信息
3:[root@gechong proc]# cat /proc/devices
显示了字符和块设备的主设备号以及分配到这些设备号的设备名称
4:[root@gechong proc]# cat /proc/dma
显示了驱动程序保留的dma通道和保留它们的驱动程序名称
5:[root@gechong proc]# more /proc/filesystems
显示了可供使用的文件系统类型,一种类型一行
6:[root@gechong proc]# more /proc/interrupts
每一行都有一个保留的中断,内容是:中断号 中断次数 登记中断的驱动程序名称
7:[root@gechong proc]# more /proc/ioports
显示了i/o相关的设备驱动器例如磁盘驱动器、以太网卡、声卡设备等

The above is the detailed content of What are the functions of subfiles or subfolders in the Linux proc directory?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template