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