📄 proc_file_system.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head> <title></title> <link rel="stylesheet" media="screen" type="text/css" href="./style.css" /> <link rel="stylesheet" media="screen" type="text/css" href="./design.css" /> <link rel="stylesheet" media="print" type="text/css" href="./print.css" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><a href=start.html>start</a></br><div class="toc"><div class="tocheader toctoggle" id="toc__header">Table of Contents</div><div id="toc__inside"><ul class="toc"><li class="clear"><ul class="toc"><li class="level2"><div class="li"><span class="li"><a href="#proc_file_system_introduction" class="toc">Proc File System : Introduction</a></span></div></li><li class="level2"><div class="li"><span class="li"><a href="#the_proc_file_system" class="toc">The Proc File System</a></span></div><ul class="toc"><li class="level3"><div class="li"><span class="li"><a href="#the_proc_directory" class="toc">The /proc Directory</a></span></div></li></ul></li><li class="level2"><div class="li"><span class="li"><a href="#creating_a_proc_directory_entry" class="toc">Creating a Proc Directory Entry</a></span></div><ul class="toc"><li class="level3"><div class="li"><span class="li"><a href="#multiple_entries" class="toc">Multiple Entries</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#a_proc_write_function" class="toc">A Proc Write function</a></span></div></li></ul></li></ul></li></ul></div></div><h2><a name="proc_file_system_introduction" id="proc_file_system_introduction">Proc File System : Introduction</a></h2><div class="level2"><p> This section introduces the /proc file system: </p><ul><li class="level1"><div class="li"> A basic /proc filesystem overview</div></li><li class="level1"><div class="li"> A proc read code example</div></li><li class="level1"><div class="li"> A proc directory entry code example</div></li><li class="level1"><div class="li"> Creating proc read code</div></li><li class="level1"><div class="li"> A proc write code example</div></li></ul></div><!-- SECTION [1-258] --><h2><a name="the_proc_file_system" id="the_proc_file_system">The Proc File System</a></h2><div class="level2"><p> The proc file system provides a means of quick access to core kernel data. What looks like a traditional file system is mounted but in reality the proc file system is entirely code and memory based. </p><p>The system uses no disk space and the code associated with it attempts to read / write to regular files but is only executed when a user process attempts to access these files.</p><p>This file system is excellent for debugging and device control since, at the basic level, simple <strong>cat</strong> and <strong>echo</strong> commands can be used to interface with the kernel. </p></div><!-- SECTION [259-841] --><h3><a name="the_proc_directory" id="the_proc_directory">The /proc Directory</a></h3><div class="level3"><p> The proc files can be examined using the following command:</p><pre class="code">ls -l /proc</pre><p> An example output is shown:</p><pre class="code">dr-xr-xr-x 5 0 0 0 1dr-xr-xr-x 5 0 0 0 10dr-xr-xr-x 5 0 0 0 9-r--r--r-- 1 0 0 0 buddyinfodr-xr-xr-x 2 0 0 0 bus-r--r--r-- 1 0 0 0 cmdline-r--r--r-- 1 0 0 0 cplbinfo-r--r--r-- 1 0 0 0 cpuinfo-r--r--r-- 1 0 0 0 devices-r--r--r-- 1 0 0 0 diskstatsdr-xr-xr-x 2 0 0 0 driver-r--r--r-- 1 0 0 0 execdomains-r--r--r-- 1 0 0 0 filesystemsdr-xr-xr-x 3 0 0 0 fs-r--r--r-- 1 0 0 0 interrupts-r--r--r-- 1 0 0 0 iomem-r--r--r-- 1 0 0 0 ioports-r--r--r-- 1 0 0 0 kallsyms-r-------- 1 0 0 0 kmsg-r--r--r-- 1 0 0 0 loadavg-r--r--r-- 1 0 0 0 locks-r--r--r-- 1 0 0 0 maps-r--r--r-- 1 0 0 0 meminfo-r--r--r-- 1 0 0 0 misclrwxrwxrwx 1 0 0 11 mounts -> self/mounts-r--r--r-- 1 0 0 0 mtddr-xr-xr-x 3 0 0 0 net-r--r--r-- 1 0 0 0 partitionslrwxrwxrwx 1 0 0 64 self -> 35-rw-r--r-- 1 0 0 0 slabinfo-r--r--r-- 1 0 0 0 statdr-xr-xr-x 4 0 0 0 tty-r--r--r-- 1 0 0 0 uptime-r--r--r-- 1 0 0 0 version-r--r--r-- 1 0 0 0 vmstat </pre><p>Individual files can be simply read using the cat command.</p><pre class="code">cat /proc/interrupts</pre><p> An example output on the Blackfin/uClinux:</p><pre class="code"> 6: 0 BFIN Timer Tick 14: 0 rtc 21: 0 BFIN_UART_RX 22: 5856 BFIN_UART_TX 27: 61 eth0Err: 0</pre><p>on a x86 PC running Linux, it looks like:</p><pre class="code"> CPU0 CPU1 0: 924059703 925864605 IO-APIC-edge timer 1: 101211 108432 IO-APIC-edge i8042 4: 555597 702548 IO-APIC-edge serial 8: 3082 3086 IO-APIC-edge rtc 9: 0 0 IO-APIC-level acpi 12: 1761518 1813890 IO-APIC-edge i8042 14: 15420700 15475179 IO-APIC-edge ide0169: 200276170 0 IO-APIC-level eth1, nvidia177: 14610420 14509225 IO-APIC-level libata193: 85016 87685 IO-APIC-level Intel ICH6, uhci_hcd201: 0 0 IO-APIC-level uhci_hcd, ehci_hcd209: 0 0 IO-APIC-level uhci_hcd217: 0 0 IO-APIC-level uhci_hcdNMI: 1849924375 1849924333LOC: 1849863422 1849863597ERR: 0MIS: 0 </pre><p> In addition to reading data the <strong>proc</strong> file system can be used to set up or alter data in the kernel. There are many system tuning parameters that can be set up by writing data to the specified <code>/proc</code> device.</p><p>Writing a string to a file <strong>/proc/sys/kernel/domainname</strong> will set up the system’s domain name.</p><pre class="code">echo -n "myblackfin.com" >/proc/sys/kernel/domainname</pre><pre class="code">cat /proc/sys/kernel/domainname myblackfin.com </pre><p> A few more details can be found in the file <strong>linux/Documentation/filesystems/proc.txt</strong>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -