A deep understanding of the proc file system overview: the linux Kernel provides a way to obtain its internal data structure and change Kernel Parameter settings when the system is running. This method relies on the proc file system. 1. proc-A Virtual File System proc file system is used to send messages to the kernel and kernel modules to processes. The reason why proc is a virtual file system is because 1) virtual means that it does not correspond to specific storage media, such as disks; 2) the file system means that it does implement the necessary file system interface. Run the following command to query: [cpp] $ mount-l/dev/sda10 on/type ext4 (rw, errors = remount-ro) proc on/proc type proc (rw, noexec, nosuid, nodev) sysfs on/sys type sysfs (rw, noexec, nosuid, nodev) none on/sys/fs/fuse/connections type fusectl (rw) none on/sys/kernel/debug type debugfs (rw) none on/sys/kernel/security type securityfs (rw) udev on/dev type devtmpfs (rw, mode = 0755) 2. proc-level Directory Overview/proc/cpuinfo/proc/meminf O/proc/mounts ---- mounted fs/proc/devices ---- avaiable devices/proc/filesystems ---- supported file systems/proc/modules ---- loaded modules/proc/version ----- kernel version/proc/ using line ---- parameters passed to the kernel at the time of starting 3. you can use the proc file system to query information about a specific process, such as environment variables, corresponding applications, cpu usage time, and process status. Example: $ ll/proc/2184 total 0dr-xr-xr-x 8 hyk 0 June 17 20:51. /dr-xr-x 214 root 0 June 18 04:50 .. /dr-xr-x 2 hyk 0 June 18 10:27 attr/-rw-r -- 1 hyk 0 June 18 10:27 autogroup-r -------- 1 hyk 0 June 17 20:51 auxv -r -- 1 hyk 0 June 18 10:27 cgroup -- w ------- 1 hyk 0 June 18 10:27 clear_refs-r -- r -- 1 hyk 0 June 17 20:51 drawing line-rw-r -- r -- 1 hyk hybrik 0 June 18 10:27 comm-rw-r -- R -- 1 hyk 0 June 18 10:27 coredump_filter-r -- r -- 1 hyk 0 June 18 10:27 cpusetlrwxrwxrwx 1 hyk 0 June 18 10:27 cwd->/home/hyk/-r -------- 1 hyk hyk 0 June 17 20:51 environlrwxrwxrwx 1 hyk 0 June 17 20:51 exe->/usr/lib/gnome-settings-daemon * dr-x ------ 2 hyk 0 June 17 20:51 fd/dr-x ------ 2 hyk 0 June 18 10:27 fdinfo/-r -------- 1 hyk 0 June 18 10:27 io-r -- 1 hyk 0 June 18 10:27 latency-r -- 1 hyk 0 June 18 10:27 limits-rw-r -- 1 hyk 0 June 18 10:27 loginuid-r -- r -- 1 hyk 0 June 18 10:27 maps-rw ------- 1 hyk 0 June 18 10:27 mem-r -- 1 hyk 0 June 18 10:27 mountinfo-r -- 1 hyk hybrik 0 June 17 20:51 mounts-r -------- 1 hyk 0 June 18 10:27 mountstatsdr-xr-x 5 hyk 0 June 18 10:27 net/dr-x -- x 2 hyk hyk 0 June 18 10:27 ns/ -Rw-r -- 1 hyk 0 June 18 10:27 oom_adj-r -- r -- 1 hyk 0 June 18 10:27 oom_score-rw-r -- r -- 1 hyk 0 June 18 10:27 oom_score_adj-r -- r -- 1 hyk 0 June 18 10:27 pagemap-r -- 1 hyk 0 June 18 10:27 personalitylrwxrwxrwx 1 hyk 0 June 18 10:27 root-> //-rw-r -- 1 hyk hybrik 0 June 18 10:27 sched-r -- 1 hyk 0 June 18 10:27 schedstat-r -- 1 hyk 0 June 18 10:27 sessionid-r -- r -- R -- 1 hyk 0 June 18 10:27 smaps-r -- 1 hyk 0 June 18 10:27 stack-r -- 1 hyk 0 June 17 20:51 stat-r -- r -- 1 hyk 0 June 18 10:27 statm-r -- 1 hyk 0 June 17 20:51 status-r -- 1 hyk 0 June 18 10:27 syscalldr -xr-x 7 hyk 0 June 18 10:27 task/-r -- 1 hyk 0 June 18 10:27 wchan related options are described as follows: cmdline: the command line environ that starts the process: All environment variables related to the Process status: Process status exe: the executable file cwd: curre corresponding to the Process Nt work directoryroot: root directory of the process, usually/fd: indicates the descriptor cpu of the file opened by a process: cpu usage time Note: If a process accesses/proc/self, it is actually accessing its own proc directory. 4. Through the proc file system, most of the content under the Kernel Parameter proc file system is read-only, but most of the content under/proc/sys is writable. $ Cat/proc/sys/kernel/hostname hyk-linuxroot @ hyk-linux: /home/hyk # echo "hyk-pc">/proc/sys/kernel/hostname $ cat/proc/sys/kernel/hostname hyk-pc 5. extract information from proc using a program [cpp] # include <stdio. h> # include <string. h>/* Returns the clock speed of the system's CPU in MHz, as reported by/proc/cpuinfo. on a multiprocessor machine, returns the speed of the first CPU. on error returns zero. */float get_cpu_clock_speed () {FILE * fp; char buffer [1024]; size_t bytes_read; char * match; float clock_speed; /* Read the entire contents of/proc/cpuinfo into the buffer. fp = fopen ("/proc/cpuinfo", "r"); bytes_read = fread (buffer, 1, sizeof (buffer), fp); fclose (fp ); /* Bail if read failed or if buffer isn't big enough. */if (bytes_read = 0 | bytes_read = sizeof (buffer) return 0;/* NUL-terminate the text. */buffer [bytes_read] = '\ 0';/* Locate the line that starts with "cpu MHz ". */match = strstr (buffer, "cpu MHz"); if (match = NULL) return 0;/* Parse the line to extract the clock speed. */sscanf (match, "cpu MHz: % f", & clock_speed); return clock_speed; */} int main () {printf ("CPU clock speed: % 4.0f MHz \ n ", get_cpu_clock_speed (); return 0 ;}