Linux proc directory subfiles or subfolders
- 2020-05-07 20:46:58
- OfStack
Introduction to the 1.Linux /proc directory
The Linux kernel provides a mechanism for accessing the kernel's internal data structures and changing kernel Settings at run time through the /proc file system. The proc file system is a pseudo-file system that only exists in memory, not in external memory. It provides an interface to operations that access system kernel data in the form of a file system.
Users and applications can get information about the system through proc and can change certain parameters of the kernel. Because system information, such as processes, changes dynamically, the proc file system dynamically reads the required information from the system kernel and submits it when the proc file is read by the user or application. Not all of the files or subfolders listed below exist on your system, depending on your kernel configuration and the modules loaded. In addition, there are three important directories under /proc: net, scsi and sys. The Sys directory is writable and allows you to access or modify kernel parameters, while net and scsi depend on kernel configuration. For example, if scsi is not supported, the scsi directory does not exist.
In addition to the above, there are also directories named after 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, which is the interface to read the process information. The self directory is an information interface for the read process itself, one link.
2. /proc directory subfiles or subfolders function
The number of blocks available for each order in each memory area is related to the fragmentation problem
Parameter information passed to kernel when /proc/cmdline is started
/proc/cpuinfo cpu information
All installed encryption passwords and details used by the /proc/crypto kernel
/proc/devices has been loaded and sorted
/proc/dma list of ISA DMA channels registered for use
The proc/execdomains Linux kernel currently supports execution domains
/proc/fb frame buffer device list, including the number and the driver that controls it
File system types currently supported by the /proc/filesystems kernel
Number of interrupts per IRQ in the proc/interrupts x86 schema
/proc/iomem the current mapping of each physical device in system memory
/proc/ioports range of registered ports used for input and output of 1 device
/proc/kcore represents the physical memory of the system, which is stored in the core file format and displays the number of bytes, equal to the size of RAM plus 4kb
/proc/kmsg records the information generated by the kernel, which can be processed by /sbin/klogd or /bin/dmesg
/proc/loadavg load status based on the state of CPU and IO over the last 1 period, related to the uptime command
/proc/locks kernel locked file list
/proc/mdstat multi-disk, RAID configuration information (md=multiple disks)
Information about the use of /proc/meminfo RAM
/proc/misc drivers registered on other major devices (device number 10)
/proc/modules list of all modules loaded into the kernel
All mounts used in the /proc/mounts system
Memory Type Range Registers (MTRRs)
Block allocation information in the /proc/partitions partition
List of PCI devices in /proc/pci system
slab cache information for all activities in the /proc/slabinfo system
/proc/stat all CPU activity information
When writing this file using the echo command, the remote root user can perform most of the system request critical commands as if they were executed at a local terminal. To write to this file, need to take/proc/sys kernel/sysrq cannot be set to 0. This file is also unreadable to root
How long has the proc/uptime system 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 equipment information
/proc/irq interrupt requests device information
/proc/net network card device information
/proc/scsi scsi equipment information
/proc/tty tty device information
/proc/net/dev shows network adapters and statistics
/proc/vmstat virtual memory statistics
/proc/vmcore kernel panic memory image
/proc/diskstats gets disk information
Statistics for /proc/schedstat kernel scheduler
/proc/zoneinfo displays statistics for memory space and is useful for analyzing virtual memory behavior
The following is information about the process N in the /proc directory
/proc/N pid is the process information of N
/proc/N/cmdline process startup command
/proc/N/cwd links to the current working directory of the process
/proc/N/environ process environment variable list
/proc/N/exe links to the execution command file of the process
/proc/N/fd contains all file descriptors associated with the process
/proc/N/maps process-related memory mapping information
/proc/N/mem refers to the memory held by the process and is not readable
/proc/N/root links to the root directory of the process
/proc/N/stat process status
The state of memory used by the /proc/N/statm process
/proc/N/status process status information, more readable than stat/statm
/proc/self links to the currently running process
3. Examples of practical operations
1. List 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
2. View system information and kernel parameters
yafang@QA:~$ ls /proc/sys
debug dev fs kernel net vm[code]
3. View network card device information
[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
4. View SCSI device information
yafang@QA:~$ ls /proc/scsi
device_info scsi
5. View a list of all modules loaded into the kernel
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:~#
6. View loaded devices and categorize them
root@BCNMB-A:~# cat /proc/devices
Character 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 mtd
116 linux-user-bde2
117 linux-kernel-bde2
126 linux-user-bde
127 linux-kernel-bde
128 ptm
136 pts
180 usb
189 usb_device
245 ext_alarm
251 ipmidev
252 usb_endpoint
253 usbmon
254 rtc
Block devices:
1 ramdisk
8 sd
31 mtdblock
65 sd
66 sd
67 sd
68 sd
69 sd
70 sd
71 sd
128 sd
129 sd
130 sd
131 sd
132 sd
133 sd
134 sd
135 sd
root@BCNMB-A:~#
7. View the block allocation information in the partition
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:~#
8. View the Linux kernel version and gcc version
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:~#
9. /proc/sys/fs/file-max
This file specifies the maximum number of file handles that can be allocated. If the user gets an error message stating that they cannot open more files because the number of open files has reached a maximum, they may need to increase the value. You can set this value to have as many files as you want, and you can change the value by writing a new numeric value to the file. The default setting is 4096.
Change kernel parameters, edit with vi or redirect to a file with echo parameters.
# cat /proc/sys/fs/file-max
4096
# echo 8192 > /proc/sys/fs/file-max
# cat /proc/sys/fs/file-max
8192
If the parameters are optimized, they can be written and added to the file rc.local to make the changes automatically when the system starts.
other examples:
1: [root@gechong proc]# more /proc/cmdline
Displays the command line for kernel startup
2: [root@gechong proc]# cat /proc/cpuinfo
The cpu information is displayed
3: [root @gechong proc]# cat /proc/devices
Displays the main device Numbers of the character and block devices and the device names assigned to those device Numbers
4: [root@gechong proc]# cat /proc/dma
Shows the driver reserved DMA channels and the driver names that reserved them
5: [root@gechong proc]# more /proc/filesystems
Shows the available file system types,1 type 1 line
6: [root @gechong proc]# more /proc/interrupts
Each line has one reserved interrupt, which is: interrupt number interrupt number register interrupt driver name
7: [root@gechong proc]# more /proc/ioports
Displays I/O related device drives such as disk drives, Ethernet CARDS, sound card devices, and so on