In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to understand the virtual file system in Linux system". In daily operation, I believe many people have doubts about how to understand the virtual file system in Linux system. Xiaobian consulted all kinds of materials and sorted out simple and easy to use operation methods. I hope to help you answer the doubts about "how to understand the virtual file system in Linux system"! Next, please follow the small series to learn together!
The Linux kernel provides a mechanism for accessing kernel internal data structures and changing kernel settings at runtime through the/proc file system. Although the basic concepts of the/proc file system are the same on Linux systems on various hardware platforms, this article only discusses Linux /proc file systems based on the Intel x86 architecture.
/proc --A virtual file system
The/proc file system is a mechanism used by the kernel and kernel modules to send information to processes (hence the name/proc). This pseudo-file system allows you to interact with kernel internal data structures, obtain useful information about processes, and change settings on the fly (by changing kernel parameters). Unlike other file systems,/proc exists in memory rather than on hard disk. If you look at the file/proc/mounts (which lists all mounted file systems as well as the mount command), you will see a line that reads:
The code is as follows:
grep proc /proc/mounts
/proc /proc proc rw 0 0
/proc is controlled by the kernel, and there is no device carrying/proc. Because/proc primarily stores kernel-controlled state information, most of the logical location of this information is in kernel-controlled memory. Running 'ls -l' on/proc shows that most files are 0 bytes long; however, when looking at these files, you do see some information. How is this possible? This is because the/proc file system registers itself at the Virtual File System Layer (VFS) in a similar way to other regular file systems. However, the/proc file system does not create files and directories based on information in the kernel until VFS calls it, requesting i-nodes for files and directories.
Load proc file system
If the proc file system is not already loaded on your system, you can load the proc file system with the following command:
The code is as follows:
mount -t proc proc /proc
The above command will successfully load your proc file system. Read the man page of the mount command for more details.
View/proc files
The/proc file can be used to access information about the state of the kernel, the properties of the computer, the state of running processes, and so on. Most of the files and directories in/proc provide up-to-date information about the physical environment of the system. Although the files in/proc are virtual, they can still be viewed using any file editor or program like 'more','less'or' cat'. When an editor tries to open a virtual file, the file is created on the fly from information in the kernel. Here are some interesting results I got from my system:
The code is as follows:
$ ls -l /proc/cpuinfo
-r--r--r-- 1 root root 0 Dec 25 11:01 /proc/cpuinfo
$ file /proc/cpuinfo
/proc/cpuinfo: empty
$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 8
model name : Pentium III (Coppermine)
stepping : 6
cpu MHz : 1000.119
cache size : 256 KB
fdiv_bug : no
hlt_bug : no
sep_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca
cmov pat pse36 mmx fxsr xmm
bogomips : 1998.85
processor : 3
vendor_id : GenuineIntel
cpu family : 6
model : 8
model name : Pentium III (Coppermine)
stepping : 6
cpu MHz : 1000.119
cache size : 256 KB
fdiv_bug : no
hlt_bug : no
sep_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca
cmov pat pse36 mmx fxsr xmm
bogomips : 1992.29
This is a result from a dual CPU system, and most of the above information clearly gives useful hardware information about the system. Some/proc files are encoded, and various tools can be used to interpret the encoded information and output it in readable form. Such tools include: 'top',' ps','apm', etc.
Get useful system/kernel information
The proc file system can be used to gather useful information about the system and running kernel. Here are some important documents:
/proc/cpuinfo - CPU information (model, family, cache size, etc.)
/proc/meminfo -Information about physical memory, swap space, etc.
/proc/mounts -List of mounted file systems
/proc/devices -List of available devices
/proc/filesystems -Supported file systems
/proc/modules -loaded modules
/proc/version -Kernel version
/proc/cmdline -Kernel command-line parameters entered at system startup
There are many more files in proc than listed above. Readers who wish to learn more can click 'more' on each file in/proc or read Reference [1] for more information about the files in the/proc directory. I recommend using 'more' rather than 'cat' unless you know that the file is small, as some files (like kcore) can be very long.
Information about running processes
The/proc file system can be used to get information about running processes. There are numbered subdirectories in/proc. Each directory number corresponds to a process id (PID). Thus, every running process/proc has a directory named after its PID. These subdirectories contain files that provide important details about the state and environment of the process. Let's try to find a running process.
The code is as follows:
$ ps -aef | grep mozilla
root 32558 32425 8 22:53 pts/1 00:01:23 /usr/bin/mozilla
The above command indicates that there is a mozilla process running with PID 32558. Correspondingly,/proc should have a directory named 32558
The code is as follows:
$ ls -l /proc/32558
total 0
-r--r--r-- 1 root root 0 Dec 25 22:59 cmdline
-r--r--r-- 1 root root 0 Dec 25 22:59 cpu
lrwxrwxrwx 1 root root 0 Dec 25 22:59 cwd -> /proc/
-r-------- 1 root root 0 Dec 25 22:59 environ
lrwxrwxrwx 1 root root 0 Dec 25 22:59 exe -> /usr/bin/mozilla*
dr-x------ 2 root root 0 Dec 25 22:59 fd/
-r--r--r-- 1 root root 0 Dec 25 22:59 maps
-rw------- 1 root root 0 Dec 25 22:59 mem
-r--r--r-- 1 root root 0 Dec 25 22:59 mounts
lrwxrwxrwx 1 root root 0 Dec 25 22:59 root -> //
-r--r--r-- 1 root root 0 Dec 25 22:59 stat
-r--r--r-- 1 root root 0 Dec 25 22:59 statm
-r--r--r-- 1 root root 0 Dec 25 22:59 status
The file "cmdline" contains the command line invoked when starting a process. The environment of the "envir" process changes two. "status" is the status information of the process, including the user ID (UID) and group ID(GID) of the user who started the process, the parent process ID (PPID), and the current status of the process, such as "Sleelping" and "Running." Each process directory has several symbolic links,"cwd" is a symbolic link to the current working directory of the process,"exe" points to the executable of the running process, and "root" points to the directory that the process considers its root directory (usually "/"). The directory "fd" contains links to file descriptors used by processes. "cpu" appears only when the SMP kernel is running and contains the process time by CPU.
/proc/self is an interesting subdirectory that makes it easy for programs to use/proc to find information about their own processes./ proc/self is a symbolic link to the directory of PID's in/proc for processes accessing/proc.
Interacting with the kernel via/proc
Most of the/proc files discussed above are read-only. In fact, the/proc file system provides interaction with the kernel through read-write files in/proc. Writing these files can change the state of the kernel, so be careful about changing them./ proc/sys directory A directory containing all readable and writable files that can be used to change kernel behavior.
/proc/sys/kernel -This directory contains information about anti-generic kernel behavior. /proc/sys/kernel/{domainname, hostname} holds the domain name and hostname of the machine/network. These files can be used to modify these names.
The code is as follows:
$ hostname
machinename.domainname.com
$ cat /proc/sys/kernel/domainname
domainname.com
$ cat /proc/sys/kernel/hostname
machinename
$ echo "new-machinename" > /proc/sys/kernel/hostname
$ hostname
new-machinename.domainname.com
In this way, we can modify the host name by modifying files in the/proc file system. Many other configurable files exist in/proc/sys/kernel/. It is impossible to list all these files here, but readers can check out this directory for more details.
Another configurable directory is/proc/sys/net. The files in this directory can be used to modify the network properties of machines/networks. For example, by simply modifying a file, you can hide your addiction on the Internet.
The code is as follows:
$ echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
This will hide your machine in web addiction because it does not respond to icmp_echo. The host will not respond to ping queries from other hosts.
The code is as follows:
$ ping machinename.domainname.com
no answer from machinename.domainname.com
To change back to the default settings, simply
The code is as follows:
$ echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_all
There are many other ways to change kernel properties under/proc/sys. The reader can obtain more information from References [1], [2].
At this point, the study of "how to understand virtual file systems in Linux systems" is over, hoping to solve everyone's doubts. Theory and practice can better match to help you learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.