/proc 文件系统是一个虚拟文件系统,通过它可以使用一种新的方法在 Linux® 内核空间和用户空间之间进行通信。在 /proc 文件系统中,我们可以将对虚拟文件的读写作为与内核中实体进行通信的一种手段,但是与普通文件不同的是,这些虚拟文件的内容都是动态创建的.
cd /proc
cat cpuinfo
cat meminfo
cat version
bzh@bzh-Rev-1-0:/proc$ cat cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 15
model name : Intel(R) Pentium(R) Dual CPU T2390 @ 1.86GHz
stepping : 13
cpu MHz : 800.000
cache size : 1024 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 2
apicid : 0
initial apicid : 0
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 10
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts aperfmperf pni dtes64 monitor ds_cpl est tm2 ssse3 cx16 xtpr pdcm lahf_lm dts
bogomips : 3724.85
clflush size : 64
cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:
processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 15
model name : Intel(R) Pentium(R) Dual CPU T2390 @ 1.86GHz
stepping : 13
cpu MHz : 800.000
cache size : 1024 KB
physical id : 0
siblings : 2
core id : 1
cpu cores : 2
apicid : 1
initial apicid : 1
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 10
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts aperfmperf pni dtes64 monitor ds_cpl est tm2 ssse3 cx16 xtpr pdcm lahf_lm dts
bogomips : 3724.39
clflush size : 64
cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:
bzh@bzh-Rev-1-0:/proc$ cat meminfo
MemTotal: 1015916 kB
MemFree: 17776 kB
Buffers: 278312 kB
Cached: 406020 kB
SwapCached: 0 kB
Active: 414148 kB
Inactive: 457688 kB
Active(anon): 188916 kB
Inactive(anon): 164044 kB
Active(file): 225232 kB
Inactive(file): 293644 kB
Unevictable: 0 kB
Mlocked: 0 kB
HighTotal: 129864 kB
HighFree: 248 kB
LowTotal: 886052 kB
LowFree: 17528 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 4 kB
Writeback: 0 kB
AnonPages: 187524 kB
Mapped: 73288 kB
Shmem: 165456 kB
Slab: 92708 kB
SReclaimable: 79384 kB
SUnreclaim: 13324 kB
KernelStack: 2384 kB
PageTables: 6132 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 507956 kB
Committed_AS: 1553512 kB
VmallocTotal: 122880 kB
VmallocUsed: 31528 kB
VmallocChunk: 67368 kB
HardwareCorrupted: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 4096 kB
DirectMap4k: 32760 kB
DirectMap4M: 876544 kB
bzh@bzh-Rev-1-0:/proc$ cat version
Linux version 2.6.38-8-generic (buildd@vernadsky) (gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu3) ) #42-Ubuntu SMP Mon Apr 11 03:31:50 UTC 2011
bzh@bzh-Rev-1-0:/proc$
bzh@bzh-Rev-1-0:/proc$ ls
1 12 1430 17 1852 1892 1932 1959 2002 2069 2179 2545 32 4557 508 828 948 cmdline execdomains key-users modules self tty
1003 1292 1440 1702 1855 1893 1933 1962 2004 2072 22 26 36 4558 550 846 974 consoles fb kmsg mounts slabinfo uptime
1005 13 1465 1790 1859 1894 1935 1964 2018 2073 23 27 4 46 6 847 987 cpuinfo filesystems kpagecount mtd softirqs version
1013 1315 15 18 1863 1899 1937 1972 2019 2088 230 28 42 4633 663 855 990 crypto fs kpageflags mtrr stat version_signature
1021 1332 1546 1809 1872 19 1939 1979 2022 2091 231 280 43 47 673 856 995 devices interrupts latency_stats net swaps vmallocinfo
1047 1334 1556 1839 1875 1900 1940 1980 2025 21 2393 289 4376 4729 7 857 acpi device-tree iomem loadavg pagetypeinfo sys vmstat
1063 1340 1564 1843 1879 1902 1943 1981 2043 2104 2397 29 44 48 759 874 asound diskstats ioports locks partitions sysrq-trigger zoneinfo
1067 1342 1568 1846 1883 1905 1946 1997 2045 2119 24 3 4406 49 813 9 buddyinfo dma irq mdstat sched_debug sysvipc
1068 1343 16 1847 1888 1909 1953 2 2047 2135 25 30 45 497 815 940 bus dri kallsyms meminfo schedstat timer_list
11 1407 1637 1850 1891 1911 1955 20 2068 2159 250 31 4550 5 821 946 cgroups driver kcore misc scsi timer_stats
一系列数字编号的文件。每个实际上都是一个目录,表示系统中的一个进程。
由于在 GNU/Linux 中创建的第一个进程是 init
进程,因此它的 process-id
为 1bzh@bzh-Rev-1-0:/proc$ ls 1/
ls: cannot read symbolic link 1/cwd: Permission denied
ls: cannot read symbolic link 1/root: Permission denied
ls: cannot read symbolic link 1/exe: Permission denied
attr cgroup comm cwd fd latency maps mounts oom_adj pagemap sched smaps statm task
autogroup clear_refs coredump_filter environ fdinfo limits mem mountstats oom_score personality schedstat stack status wchan
auxv cmdline cpuset exe io loginuid mountinfo net oom_score_adj root sessionid stat syscall
bzh@bzh-Rev-1-0:/proc$ cat 1/cmdline
/sbin/initbzh@bzh-Rev-1-0:/proc$
bzh@bzh-Rev-1-0:/proc$
modules
,标识了当前加载到内核中的模块。
bzh@bzh-Rev-1-0:/proc$ cat modules
binfmt_misc 13213 1 - Live 0x00000000
vboxnetadp 13348 0 - Live 0x00000000
vboxnetflt 27855 0 - Live 0x00000000
vboxdrv 234314 2 vboxnetadp,vboxnetflt, Live 0x00000000
parport_pc 32111 0 - Live 0x00000000
ppdev 12849 0 - Live 0x00000000
snd_hda_codec_si3054 12924 1 - Live 0x00000000
snd_hda_codec_realtek 255820 1 - Live 0x00000000
snd_hda_intel 24140 2 - Live 0x00000000
snd_hda_codec 90901 3 snd_hda_codec_si3054,snd_hda_codec_realtek,snd_hda_intel, Live 0x00000000
snd_hwdep 13274 1 snd_hda_codec, Live 0x00000000
snd_pcm 80244 3 snd_hda_codec_si3054,snd_hda_intel,snd_hda_codec, Live 0x00000000
snd_seq_midi 13132 0 - Live 0x00000000
snd_rawmidi 25269 1 snd_seq_midi, Live 0x00000000
i915 450944 3 - Live 0x00000000
joydev 17322 0 - Live 0x00000000
snd_seq_midi_event 14475 1 snd_seq_midi, Live 0x00000000
snd_seq 51291 2 snd_seq_midi,snd_seq_midi_event, Live 0x00000000
gspca_m5602 59649 0 - Live 0x00000000
gspca_main 27894 1 gspca_m5602, Live 0x00000000
videodev 75143 1 gspca_main, Live 0x00000000
snd_timer 28659 2 snd_pcm,snd_seq, Live 0x00000000
r852 17878 0 - Live 0x00000000
sm_common 16737 1 r852, Live 0x00000000
snd_seq_device 14110 3 snd_seq_midi,snd_rawmidi,snd_seq, Live 0x00000000
ideapad_laptop 13262 0 - Live 0x00000000
sparse_keymap 13666 1 ideapad_laptop, Live 0x00000000
nand 49822 2 r852,sm_common, Live 0x00000000
nand_ids 8547 1 nand, Live 0x00000000
nand_ecc 13070 1 nand, Live 0x00000000
snd 55295 14 snd_hda_codec_si3054,snd_hda_codec_realtek,snd_hda_intel,snd_hda_codec,snd_hwdep,snd_pcm,snd_rawmidi,snd_seq,snd_timer,snd_seq_device, Live 0x00000000
mtd 26720 2 sm_common,nand, Live 0x00000000
drm_kms_helper 40745 1 i915, Live 0x00000000
drm 180037 4 i915,drm_kms_helper, Live 0x00000000
psmouse 73312 0 - Live 0x00000000
soundcore 12600 1 snd, Live 0x00000000
i2c_algo_bit 13184 1 i915, Live 0x00000000
video 18951 1 i915, Live 0x00000000
snd_page_alloc 14073 2 snd_hda_intel,snd_pcm, Live 0x00000000
serio_raw 12990 0 - Live 0x00000000
lp 13349 0 - Live 0x00000000
parport 36746 3 parport_pc,ppdev,lp, Live 0x00000000
usbhid 41704 0 - Live 0x00000000
hid 77084 1 usbhid, Live 0x00000000
sdhci_pci 13623 0 - Live 0x00000000
firewire_ohci 31504 0 - Live 0x00000000
tg3 131476 0 - Live 0x00000000
firewire_core 56138 1 firewire_ohci, Live 0x00000000
ssb 45942 0 - Live 0x00000000
sdhci 22720 1 sdhci_pci, Live 0x00000000
crc_itu_t 12627 1 firewire_core, Live 0x00000000