Linux proc文件系统介绍

news/2025/2/12 13:11:25/

Linux proc文件系统

/proc/cmdline

Arguments  passed to the Linux kernel at boot time.  Often done via a boot manager such as lilo(8) or grub(8)


            

proc/[pid]/coredump_filter

      Since kernel 2.6.23, the Linux-specific /proc/PID/coredump_filter file can be used  to
       control  which  memory  segments are written to the core dump file in the event that a
       core dump is performed for the process with the corresponding process ID.

       The value in the file is a bit mask of memory mapping types (see mmap(2)).  If  a  bit
       is  set in the mask, then memory mappings of the corresponding type are dumped; other‐
       wise they are not dumped.  The bits in this file have the following meanings:

           bit 0  Dump anonymous private mappings.
           bit 1  Dump anonymous shared mappings.
           bit 2  Dump file-backed private mappings.
           bit 3  Dump file-backed shared mappings.
           bit 4 (since Linux 2.6.24)
                  Dump ELF headers.
           bit 5 (since Linux 2.6.28)
                  Dump private huge pages.
           bit 6 (since Linux 2.6.28)
                  Dump shared huge pages.


/proc/[pid]/environ

包含了该进程的环境变量。

/proc/[pid]/fd/

 /proc/interrupts

This is used to record the number of interrupts per CPU per IO  device.   Since Linux  2.6.24,  for  the  i386  and  x86_64  architectures, at least, this also includes interrupts internal to the system (that  is,  not  associated  with  a device  as  such), such as NMI (nonmaskable interrupt), LOC (local timer interrupt), and for SMP systems, TLB (TLB flush interrupt), RES (rescheduling interrupt), CAL (remote function call interrupt), and possibly others.  Very easy to read formatting, done in ASCII.

 /proc/kallsyms (since Linux 2.5.71)

这包含使用模块(X)工具导出的内核符号定义。包括动态地链接和绑定可加载的模块。在Linux 2.5.47及更早的版本中,类似文件被命名为ksyms。

/proc/kmsg

可以使用此文件来代替syslog (2)系统调用来读取内核消息。进程必须具有超级用户权限才能读取此文件,并且只有一个进程应该读取此文件。如果一个使用syslog (2)系统调用工具来记录内核消息的syslog进程正在运行,则不应该读取此文件。

使用dmesg命令可以获取文件中的信息。

/proc/sys/kernel/dmesg_restrict (since Linux 2.6.37)

控制谁可以看到dmesg信息。值为0表示不受控,所有用户都可以看到。值为1标志是有超级用户才能看到,从linux 3.4开始,只有系统管理员才能看到dmesg。

/proc/sys/kernel/domainname and /proc/sys/kernel/hostname 

              can  be  used  to  set  the  NIS/YP  domainname and the hostname of your box in
              exactly the same way as the commands domainname(1) and hostname(1), that is:

                  # echo 'darkstar' > /proc/sys/kernel/hostname
                  # echo 'mydomain' > /proc/sys/kernel/domainname

              has the same effect as

                  # hostname 'darkstar'
                  # domainname 'mydomain'

              Note, however, that the classic darkstar.frop.org has the  hostname  "darkstar"
              and DNS (Internet Domain Name Server) domainname "frop.org", not to be confused
              with the NIS (Network Information Service) or  YP  (Yellow  Pages)  domainname.
              These two domain names are in general different.  For a detailed discussion see
              the hostname(1) man page.

/proc/sys/kernel/hotplug

 This file contains the path for the hotplug policy agent.  The default value in this file is /sbin/hotplug.

/proc/sys/kernel/modprobe

                This file contains the path for the kernel module loader.  The default value is
              /sbin/modprobe.   The file is present only if the kernel is built with the CON‐
              FIG_MODULES (CONFIG_KMOD in Linux 2.6.26 and earlier) option  enabled.   It  is
              described  by the Linux kernel source file Documentation/kmod.txt (present only
              in kernel 2.4 and earlier).

/proc/sys/kernel/modules_disabled

一个切换值,指示是否允许加载模块,否则,模块既不能加载或卸载,切换不能加载

重新设置为false。只有当内核启用CONFIG_MODULES选项才有此选项。

/proc/sys/kernel/msgmax

定义消息队列一个消息的最大长度。

/proc/sys/kernel/msgmni

定义了消息队列的个数。

/proc/sys/kernel/msgmnb

此文件定义了一个系统范围内的参数,用于初始化随后创建的消息队列的msg_qbytes设置。msg_qbytes设置指定可以写入消息队列的最大字节数。

/proc/sys/kernel/panic 

此文件提供对内核变量panic_timeout的读写访问。如果这是零,内核panic的时候会死循环;如果为非零,则表示内核应该在这个秒数之后自动重新启动。当您使用软件看门狗设备驱动程序时,建议的设置为60。

/proc/sys/kernel/panic_on_oops

此文件控制在遇到oops或BUG时内核的行为。

如果它包含1,然后系统延迟几秒钟(给klogd时间来记录然后panic。如果/proc/sys/内核/panic文件也是非零,然后机器将被重新启动。

/proc/sys/kernel/pid_max 

定义了PID的最大值(该文件中的值比系统中最大PID大1)。该文件的默认值32768的结果范围与之前的内核相同。在32位平台上,32768是pid_max的最大值。在64位系统上,pid_max可以设置为高达2^22(PID_MAX_LIMIT,大约400万)的任何值。

 

/proc/sys/kernel/printk

这四个值分别代表:console_loglevel,  default_message_loglevel, minimum_console_level,  and  default_console_loglevel.

 These values influence printk() behavior when printing or logging error messages.

优先级高于console_loglevel的消息将被打印到控制台。没有显式优先级的消息将被打印为优先级默认消息级别。minimum_console_loglevel是console_loglevel可以设置到的最小(最高)值。default_console_loglevel是console_loglevel的默认值。

/proc/sys/kernel/real-root-dev

/proc/sys/kernel/sysrq

This  file  controls  the functions allowed to be invoked by the SysRq key.  By default, the file contains 1 meaning  that  every  possible  SysRq  request  is allowed。

/proc/sys/vm/panic_on_oom (since Linux 2.6.18)

             This enables or disables a kernel panic in an out-of-memory situation.

              If this file is set to the value 0, the  kernel's  OOM-killer  will  kill  some
              rogue process.  Usually, the OOM-killer is able to kill a rogue process and the
              system will survive.

              If this file is set to the value 1, then the kernel normally panics  when  out-
              of-memory  happens.   However, if a process limits allocations to certain nodes
              using memory policies (mbind(2) MPOL_BIND) or  cpusets  (cpuset(7))  and  those
              nodes  reach  memory  exhaustion  status, one process may be killed by the OOM-
              killer.  No panic occurs in this case: because other nodes' memory may be free,
              this  means  the system as a whole may not have reached an out-of-memory situa‐
              tion yet.

              If this file is set to the value 2, the kernel always panics  when  an  out-of-
              memory condition occurs.

              The default value is 0.  1 and 2 are for failover of clustering.  Select either
              according to your policy of failover.

 /proc/sysrq-trigger

怎么触发一个sysrq事件?

如果你在机器上有root权限,你能把commandkey字符写入到/proc/sysrq-trigger文件。这能帮助你通过脚本或你不在系统终端上的时候触发sysrq事件。

echo ‘m’ > /proc/sysrq-trigger

当我触发一个sysrq事件的时候,结果保存在什么地方?

当一个sysrq命令被触发,内核将会打印信息到内核的环形缓冲并输出到系统控制台。此信息一般也会通过syslog输出到/var/log/messages。

sysrq功能被打开后,有几种sysrq事件能被触发。不同的内核版本可能会有些不同。但有一些是共用的:

m - 导出关于内存分配的信息,

t - 导出线程状态信息,

p - 导出当前CPU寄存器信息和标志位的信息,

c - 故意让系统崩溃(在使用netdump或diskdump的时候有用),

s - 即时同步所有挂载的文件系统,

u - 即时重新挂载所有的文件系统为只读,

b - 即时重新启动系统,

o - 即时关机(如果机器设置并支持此项功能)。

立即重新启动计算机

echo “b” > /proc/sysrq-trigger

立即关闭计算机

echo “o” > /proc/sysrq-trigger

导出内存分配的信息 (可以用/var/log/message 查看)

echo “m” > /proc/sysrq-trigger

导出当前CPU寄存器信息和标志位的信息

echo “p” > /proc/sysrq-trigger

导出线程状态信息

echo “t” > /proc/sysrq-trigger

故意让系统崩溃

echo “c” > /proc/sysrq-trigger

立即重新挂载所有的文件系统

echo “s” > /proc/sysrq-trigger

立即重新挂载所有的文件系统为只读

echo “u” > /proc/sysrq-trigger


http://www.ppmy.cn/news/40507.html

相关文章

Loblaws Inc EDI需求详解

Loblaws Inc是成立于1919年的加拿大连锁超市公司,经营范围涵盖食品、健康、美容、金融服务和服装等多个领域。 Loblaws Inc在加拿大拥有超过2200家门店和200000名员工,是加拿大最大的私营雇主之一。虽然Loblaws Inc在中国没有直接的业务,但是…

Python安装模块总失败?一次教你学会镜像安装

人生苦短,我用python 安装模块总是不成功? 这次一次性讲清楚~ 还是安装报错指路:点击此处跳转文末名片获取 为什么会出现安装模块失败? 首先我们要知道 其实大部分我们在用的模块, 都是歪果仁开发的, 然而我们在输入 “pip install 模块名” 的时候,…

自己动手写CPU——第二篇

1 ori指令说明 ori是进行逻辑 或 运算的指令,其指令格式如下所示 从以上的指令格式,我们可以直到,这是一个I类型指令,ori指令的指令码是 6‘b001101,所以当处理器发现正在处理的指令的高6bit 是 001101 的时候&#x…

PyTorch LSTM单步预测

前言 LSTM 航空乘客预测单步预测的两种情况。 简单运用LSTM 模型进行预测分析。加入注意力机制的LSTM 对航空乘客预测采用了目前市面上比较流行的注意力机制,将两者进行结合预测。多层 LSTM 对航空乘客预测 简单运用多层的LSTM 模型进行预测分析。双向LSTM 对航空乘…

ETL 与 ELT的关键区别

ETL 和 ELT 之间的主要区别在于数据转换发生的时间和地点 — 这些变化可能看起来很小,但会产生很大的影响! ETL 和 ELT 是数据团队引入、转换并最终向利益干系人公开数据的两种主要方式。它们是与现代云数据仓库和 ETL 工具的开发并行发展的流程。 在任…

DevEco Device Tool 3.1 Release新版本发布,新增资源管理器、SFTP、HDC

DevEco Device Tool是面向智能设备开发者提供的一站式集成开发环境,支持代码编辑、编译、烧录和调试、性能监测等功能,支持C/C语言,以插件的形式部署在Visual Studio Code(简称VSCode)上,支持Windows10 64位…

低代码(七)低代码平台后端技术选型2.0

JWT 登录token Json web token (JWT), 是为了在网络应用环境间传递声明而执行的一种基于JSON的开放标准((RFC 7519).该token被设计为紧凑且安全的,特别适用于分布式站点的单点登录(SSO)场景。JWT的声明一般被用来在身份提供者和服…

牛客网在线编程SQL篇非技术快速入门题解(二)

大家好,我是RecordLiu。 初学SQL,有哪些合适的练习网站推荐呢? 如果你有编程基础,那么我推荐你到Leetcode这样的专业算法刷题网站,如果没有,也不要紧,你也可以到像牛客网一样的编程网站去练习。 牛客网有很多面向非技…