linux的/proc文件_Linux中“ / proc”文件系统指南

Linux的/proc文件系统是一个虚拟文件系统,提供关于系统进程、内存管理和硬件配置的信息。通过`ls`和`cd`命令可以访问和浏览其内容,包括进程ID目录、内存统计、CPU信息和各种系统状态文件。每个编号目录代表一个进程ID,其中包含了与该进程相关的详细信息。/proc/meminfo揭示内存使用情况,/proc/cpuinfo提供CPU信息,而其他文件如/proc/interrupts、/proc/ioports和/proc/diskstats则提供中断、I/O端口和磁盘设备的统计数据。了解/proc文件系统对于深入了解Linux系统操作至关重要。
摘要由CSDN通过智能技术生成

linux的/proc文件

/proc, in short for “process”, is a virtual file-system, that is created every time the system starts up. It contains information related to the ongoing processes, memory management as well as some hardware configurations.

/proc (“进程”的缩写)是一个虚拟文件系统,每次系统启动时都会创建。 它包含与正在进行的进程,内存管理以及某些硬件配置有关的信息。

Every Linux has /proc file-system no matter the type or version. Being a virtual file-system, it can be accessed from any directory in Linux. To get inside the file-system, we run the command:

每个Linux都具有/proc文件系统,无论类型或版本如何。 作为虚拟文件系统,可以从Linux中的任何目录访问它。 为了进入文件系统,我们运行以下命令:

如何访问“ / proc”文件系统? (How to visit ‘/proc’ file-system?)

The first thing we will learn is how to navigate to the /proc file-system.

我们将学习的第一件事是如何导航到/ proc文件系统。


cd /proc

'cd' refers to as “change directory”, which is used to switch to other directories in Linux.

'cd'是指“更改目录”,用于在Linux中切换到其他目录。



/ proc文件系统的内容 (Contents of /proc file-system)

Instead of changing directory, we can instead list all the files of /proc file-system on the terminal using:

无需更改目录,我们可以使用以下命令列出终端上/proc文件系统的所有文件:


ls /proc

'ls' command is used to list all files and directories present inside the specified location. More on ls here.

'ls'命令用于列出指定位置内存在的所有文件和目录。 在这里更多有关ls的信息。

The 'ls' command uses a color scheme for representation of files and directories.

'ls'命令使用颜色方案表示文件和目录。



配色方案 (Color scheme)

  • Blue – The blue part of the output represents sub-directories.

    蓝色 –输出的蓝色部分代表子目录
  • White – The files that are uncolored are normal files containing data.

    白色 –未着色的文件是包含data的普通文件
  • Cyan – The cyan colored files are symbolic links.

    青色 –青色文件是符号链接

As we can see /proc contains a huge number of files and directories. We will go through some important ones.

如我们所见, /proc包含大量文件和目录。 我们将介绍一些重要的内容。



编号目录 (Numbered Directories)

Each numbered directory denotes a Process ID. Process ID (PID) is a unique ID given a particular process that is either running or sleeping in the system. Each process directory contains files that store information about the respective process.

每个编号的目录表示一个进程ID。 进程ID(PID)是给定在系统中正在运行或Hibernate的特定进程的唯一ID。 每个进程目录都包含存储有关相应进程信息的文件。

It must be noted that each process is crucial for the proper functioning of the system. Therefore, for complete access of each file in process directories, we need root access. It can be achieved by 'sudo -s' or 'sudo su' in Linux. More information on sudo.

必须注意的是,每个过程对于系统的正常运行至关重要。 因此,要完全访问进程目录中的每个文件,我们需要root用户访问权限。 可以通过Linux中的'sudo -s''sudo su'来实现。 有关sudo的更多信息。

Let us look at an example for process with PID = 15.

让我们看一个PID = 15的过程示例。

内容清单 (List of contents)

Extracting the contents of the directory numbered 15, can be done by:

提取编号为​​15的目录的内容可以通过以下方法完成:


ls /proc/15
Proc Ls 15
Contents of directory ’15’
目录“ 15”的内容

处理信息 (Process Information)

To extract information regarding the process 15, we run:

要提取有关流程15的信息,我们运行:


cat /proc/15/status
Proc Info 15
Information about process ’15’
有关流程“ 15”的信息

'cat' is Linux tool for concatenating files. Here, we just used it to extract data stored in 'status' file inside '15' directory.

'cat'是用于串联文件的Linux工具。 在这里,我们只是用它来提取存储在'15'目录中'status'文件中的数据。

To verify the authenticity of the output, we can always check the process status using the ps command by:

为了验证输出的真实性,我们始终可以通过以下命令使用ps命令检查进程状态:


ps -p 15
Proc Ps 15
Process status of ’15’ using ‘ps’
使用“ ps”的处理状态为“ 15”

The above command filters out the process status according to the given PID.

上面的命令根据给定的PID过滤出过程状态。

其他详情 (Other details)

Each file inside '/proc/15' contains some information related to process '15'. Some of the files are:

'/proc/15'中的每个文件都包含一些与进程'15'有关的信息。 其中一些文件是:

  • /proc/15/mem – The memory the process already holds.

    / proc / 15 / mem –进程已保存的内存
  • /proc/15/environ – The environment variables set during the initiation of the process.

    / proc / 15 / environ –在启动过程中设置环境变量
  • /proc/15/cwd – The link to the current working directory (CWD) of the process.

    / proc / 15 / cwd –指向进程的当前工作目录 (CWD)的链接。
  • /proc/15/limits – Stores the values of resource-limits like CPU Time or Memory space.

    / proc / 15 / limits –存储资源限制的值,例如CPU时间或内存空间。
  • /proc/15/fd – The directory which contains file descriptors.

    / proc / 15 / fd –包含文件描述符的目录。
  • /proc/15/cmdline – It contains the whole command line for the process.

    / proc / 15 / cmdline –包含该过程的整个命令行

To learn more about such files inside process-related directories, we can refer the manual pages using 'man proc'.

要了解有关进程相关目录中此类文件的更多信息,我们可以使用'man proc'来参考手册页。



内存统计 (Memory Statistics )

‘/proc/meminfo’ contains information about the system’s memory usage. This file can be accessed by:

'/ proc / meminfo' 包含有关系统内存使用情况的信息。 可以通过以下方式访问此文件:


cat /proc/meminfo
Proc Meminfo
Contents of ‘meminfo’ file
“ meminfo”文件的内容


CPU信息 (CPU Information)

To access details related to CPU dependent items like CPU clock speed, model, etc, ‘/proc/cpuinfo’ can be used:

要访问与CPU相关项目有关的详细信息,例如CPU时钟速度,型号等,可以使用'/ proc / cpuinfo'


cat /proc/cpuinfo
Proc Cpuinfo
Contents of ‘cpuinfo’ file
'cpuinfo'文件的内容


内核锁定的文件 (Files locked by kernel)

In a multi-threading environment, locking is the key to solve the simultaneous editing of a file. '/proc/locks' contains the list of locks that are currently being implemented by the kernel.

在多线程环境中,锁定是解决文件同时编辑的关键。 '/proc/locks'包含内核当前正在实现的锁的列表。


cat /proc/locks
Proc Locks
Current locks
当前锁

Each line contains a single lock. It can be interpreted as:

每行包含一个锁。 它可以解释为:

  • 1: – The serial number in the locks file.

    1:locks文件中的序列号
  • POSIX – The type of lock implementation.

    POSIX锁实现的类型。
  • ADVISORYPrevents an attempt to lock the file again.

    ADVISORY防止 再次尝试锁定文件。
  • WRITE – The type of lock on the basis of access, either READ or WRITE.

    WRITE基于 访问的锁定类型,即READ或WRITE。
  • 2056 – The PID of the process that holds the lock.

    2056持有锁的进程的PID
  • 08:07:5899560 – The identification of the file.

    08:07:5899560 –文件的标识
  • 0 EOF – The starting and ending point of the locked-region of the file.

    0 EOF –文件的锁定区域起点终点


密码模块 (Cryptographic modules)

'/proc/crypto' contains the list of ciphers that are supported by the kernel crypto API. Its contents look like this:

'/proc/crypto'包含内核加密API支持的密码列表。 其内容如下所示:


cat /proc/crypto
Proc Crypto
Contents of ‘crypto’ file
“ crypto”文件的内容


支持的文件系统 (Supported file-systems)

'/proc/filesystems' contains the list of other file-systems currently supported or mounted by the Linux kernel.

'/proc/filesystems'包含Linux内核当前支持或挂载的其他文件系统的列表。


cat /proc/filesystems
Proc File Systems
Other File-systems
其他文件系统

The second column of the output contains the name of the file-systems supported, whereas the first column specifies whether it is currently mounted or not.

输出的第二列包含受支持的文件系统的名称,而第一列指定当前是否已安装该文件系统。

The use of 'nodev' means, that the following file-system is not mounted.

使用'nodev'意味着未安装以下文件系统。



'/ proc'中的其他文件 (Other files in ‘/proc’)

Some of the other files containing important information are:

其他一些包含重要信息的文件是:

  • /proc/interrupts – Contains interrupts for each CPU.

    / proc / interrupts –包含每个CPU的 中断
  • /proc/ioports – Stores the list of all Input/Output ports in use.

    / proc / ioports –存储所有正在使用的输入/输出端口的列表。
  • /proc/diskstats – Displays statistics for each disk device.

    / proc / diskstats –显示每个磁盘设备的统计信息。
  • /proc/version – Stores the kernel version.

    / proc / version-存储内核版本
  • /proc/tty – Sub-directory containing files related to terminal drivers.

    / proc / tty –包含与终端驱动程序相关的文件的子目录。


结论 (Conclusion)

This article on proc file-system only touches the surface of the topic. It might be enough for a casual Linux user. In a case, you still have a curiosity about the possibilities of proc file-system, then you can make use of the man command (man proc).

这篇关于proc文件系统的文章仅涉及主题的表面。 对于一个随意的Linux用户来说可能就足够了。 在某种情况下,您仍然对proc文件系统的可能性抱有好奇心,然后可以使用man命令(man proc)

Thank you for reading. Feel free to comment below for more queries or criticisms.

感谢您的阅读。 欢迎在下面发表评论,以获取更多疑问或批评。

翻译自: https://www.journaldev.com/41537/proc-file-system-in-linux

linux的/proc文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值