Directory /proc

From 탱이의 잡동사니
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Overview

/proc 디렉토리 내용 정리.

Basic

/proc 디렉토리는 굉장히 특별한 가상 파일 시스템이다. 실제로 존재하는 파일들을 모아놓은 파일 시스템은 아니지만, 시스템적으로 굉장히 유용한 가상 파일들이 모여있는 특별한 디렉토리이다. 이 디렉토리를 참조하여 현재 작동중인 프로세스와 시스템의 상황과 여러가지 사용중인 리소스의 내용들을 확인할 수 있다.

$ ls /proc/
1      1075   12106  129    7192  9       buddyinfo    interrupts   meminfo       swaps
10     1078   12115  1292   7198  9166    bus          iomem        misc          sys
1008   1084   12116  13     7297  9258    cgroups      ioports      modules       sysrq-trigger
1022   1098   12240  130    731   944     cmdline      irq          mounts        sysvipc
10233  11     1243   13069  732   953     consoles     kallsyms     mtrr          thread-self
10235  1114   12448  131    7480  956     cpuinfo      kcore        net           timer_list
10422  1123   12562  13165  7695  959     crypto       keys         pagetypeinfo  timer_stats
10431  11507  1257   132    77    967     devices      key-users    partitions    tty
10465  11550  12575  13215  7732  971     diskstats    kmsg         sched_debug   uptime
10588  118    12582  133    78    974     dma          kpagecgroup  schedstat     version
10610  1180   12588  134    7882  976     driver       kpagecount   scsi          version_signature
1069   11850  127    13535  79    982     execdomains  kpageflags   self          vmallocinfo
1070   119    12720  138    7935  989     fb           loadavg      slabinfo      vmstat
10701  12     128    14     7963  acpi    filesystems  locks        softirqs      zoneinfo
10713  12105  12888  14174  8     asound  fs           mdstat       stat

/proc/acpi

전원 관리와 관련된 정보가 들어있는 디렉토리이다.

$ ls /proc/acpi/ -l
total 0
dr-xr-xr-x 3 root root 0 May 24 16:15 ac_adapter
dr-xr-xr-x 3 root root 0 May 24 16:15 battery
dr-xr-xr-x 3 root root 0 May 24 16:15 button
dr-xr-xr-x 2 root root 0 May 24 16:15 ibm
-rw-r--r-- 1 root root 0 May 24 16:15 wakeup

/proc/asound

$ ls -l /proc/asound/
total 0
lrwxrwxrwx 1 root root 5 May 24 16:32 Audio -> card2
dr-xr-xr-x 5 root root 0 May 24 16:32 card0
dr-xr-xr-x 4 root root 0 May 24 16:32 card1
dr-xr-xr-x 4 root root 0 May 24 16:32 card2
dr-xr-xr-x 2 root root 0 May 24 16:32 card29
-r--r--r-- 1 root root 0 May 24 16:32 cards
-r--r--r-- 1 root root 0 May 24 16:32 devices
lrwxrwxrwx 1 root root 5 May 24 16:32 HDMI -> card0
-r--r--r-- 1 root root 0 May 24 16:32 hwdep
-r--r--r-- 1 root root 0 May 24 16:32 modules
lrwxrwxrwx 1 root root 5 May 24 16:32 PCH -> card1
-r--r--r-- 1 root root 0 May 24 16:32 pcm
dr-xr-xr-x 2 root root 0 May 24 16:32 seq
lrwxrwxrwx 1 root root 6 May 24 16:32 ThinkPadEC -> card29
-r--r--r-- 1 root root 0 May 24 16:32 timers
-r--r--r-- 1 root root 0 May 24 16:32 version

/proc/buddyinfo

버디 할당자에 대한 정보를 포함한다.

$ cat buddyinfo 
Node 0, zone      DMA      1      1      0      0      2      1      1      0      1      1      3 
Node 0, zone    DMA32   7290   1421    564    276    199    125     50      1      0      0      0 
Node 0, zone   Normal  13577   3188    879    418    248    156     86      1      0      0      0 

/proc/bus

$ ls -l /proc/bus
total 0
dr-xr-xr-x 2 root root 0 May 24 16:32 input
dr-xr-xr-x 7 root root 0 May 24 16:32 pci

/proc/cgroups

$ cat /proc/cgroups 
#subsys_name	hierarchy	num_cgroups	enabled
cpuset	2	5	1
cpu	3	5	1
cpuacct	4	5	1
memory	5	5	1
devices	6	5	1
freezer	7	5	1
blkio	8	5	1
perf_event	9	5	1
hugetlb	10	5	1

/proc/cmdline

커널에 넘겨진 파라미터 값들을 보여주는 파일이다.

$ cat /proc/cmdline 
BOOT_IMAGE=/boot/vmlinuz-3.13.0-119-generic root=UUID=76594bac-4ad0-41fd-a913-e6e23c052127 ro splash quiet vt.handoff=7

위의 예제에서 확인할 수 있는 내용은 다음과 같다.

  • ro : read-only.
  • splash :
  • quiet :
  • vt.handoff=7 :

/proc/consoles

등록되어 있는 system console 들을 보여준다.

다음과 같은 부분으로 나뉘어 진다.

<device>            <operations>   <flags>  <major:minor>
  • device : name of the device.
  • operation
R : Can do read operations.
W : Can do write operations.
U : Can do unblank.
  • flags
E : It is enabled.
C : It is preferred console.
p : It is used for printk buffer.
b : It is not a TTY but a Braille device.
a : It is safe to use when cpu is offline.
  • major:minor : Major and minor number of the device separated by a colon.
$ cat /proc/consoles 
tty0                 -WU (EC p  )    4:7

/proc/cpuinfo

현재 작동중인 프로세서(cpu)의 상세 정보가 들어있다.

$ cat /proc/cpuinfo

processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 60
model name	: Intel(R) Core(TM) i7-4702MQ CPU @ 2.20GHz
stepping	: 3
microcode	: 0x17
cpu MHz		: 800.000
cache size	: 6144 KB
physical id	: 0
siblings	: 8
core id		: 0
cpu cores	: 4
apicid		: 0
initial apicid	: 0
fpu		: yes
fpu_exception	: yes
cpuid level	: 13
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall
 nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor
 ds_cpl vmx est tm2 ssse3 fma cx16 xtpr pdcm pcid sse4_1 sse4_2 movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm ida arat
 epb xsaveopt pln pts dtherm tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid
bogomips	: 4390.16
clflush size	: 64
cache_alignment	: 64
address sizes	: 39 bits physical, 48 bits virtual
power management:

...

/proc/meminfo

시스템에서 사용중인 메모리의 상세 정보를 보여준다.

표시되는 kB 바이트 단위는 1024 바이트를 뜻한다.

Linux 프로그래밍 관습에 의하면 KB는 1024, kB 는 1000 으로 인식되지만, /proc/meminfo 는 특별하다. 이곳에서만큼은 kB로 표시되는 바이트 단위가 1000 이 아니라, 1024 이다<ref>https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s2-proc-meminfo.html</ref>.

사실 kB/KB 표기에 대해서는 굉장히 명확한 표준이 있다 - ISO-80000<ref>https://en.wikipedia.org/wiki/ISO/IEC_80000</ref>. 하지만, ISO-80000 표준은 리눅스가 개발된지 굉장히 뒤에 제정된 룰이기에(2009.11) 리눅스가 개발될 당시에는 이런 규칙이 없었다. 그리고, 이후에는 이를 바꾸는 것이 굉장히 큰 위험(Risk)가 있었기에 그냥 그대로 사용하는 중이다.

(10:30:21 AM) pchero_work: Hi guys, I just visited here for stupid question.. Just wondering. Why the /proc/<pid>/meminfo doesn't follow the KB/kB standard? 
Is there any special reason? Because, I thought the KB/kB printing is just convention. But it was actually ISO-standard. https://en.wikipedia.org/wiki/ISO/IEC_80000
(10:40:35 AM) oiaohm: pchero_work: its because the KB usage there is older than the ISO standard.  Fixing it could break some applcications.
(10:40:49 AM) oiaohm: pchero_work: opps kB
(10:44:19 AM) oiaohm: pchero_work: https://en.wikipedia.org/wiki/Kilobyte   ISO with KB=1000 and KiB=1024 is 1998.  of Linux starts 
before that and used JEDEC  that was the standard back then.
(10:45:04 AM) oiaohm: pchero_work: standards sometimes change over time and that leaves behind some of these oddities.
(10:47:20 AM) pchero_work: oiaohm: Thanks a lot! Makes sense! :)
(10:47:47 AM) oiaohm: pchero_work: the Linus rule of do not break user-space makes it a little hard to fix.

Example

$ cat meminfo 
MemTotal:        7888452 kB
MemFree:          727020 kB
Buffers:           47332 kB
Cached:          1357364 kB
SwapCached:        71268 kB
Active:          4664736 kB
Inactive:        1850328 kB
Active(anon):    4449136 kB
Inactive(anon):  1373952 kB
Active(file):     215600 kB
Inactive(file):   476376 kB
Unevictable:         308 kB
Mlocked:             308 kB
SwapTotal:       9811064 kB
SwapFree:        9070744 kB
Dirty:              1892 kB
Writeback:             8 kB
AnonPages:       5043908 kB
Mapped:           634332 kB
Shmem:            712716 kB
Slab:             384608 kB
SReclaimable:     312280 kB
SUnreclaim:        72328 kB
KernelStack:       12544 kB
PageTables:       113188 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:    13755288 kB
Committed_AS:   22361548 kB
VmallocTotal:   34359738367 kB
VmallocUsed:      411952 kB
VmallocChunk:   34359310844 kB
HardwareCorrupted:     0 kB
AnonHugePages:    968704 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:       90980 kB
DirectMap2M:     2762752 kB
DirectMap1G:     5242880 kB

/proc/uptime

시스템이 운영된 시간을 보여준다(부팅 이후의 시간).

cat /proc/uptime 을 해보면 숫자가 다음과 같이 두개가 나온다.

$ cat /proc/uptime 
28047.65 174710.22

첫 번째 숫자는 시스템이 시작된지 흐른 시간이다. 즉, up time 을 초(second)로 나타낸 숫자이다.

그리고 두 번째 숫자는 idle 상태로 있은 시간이다. 즉, idle time 을 초(second)로 나타낸 숫자이다.

See also

/proc/<pid>/limits

현재 실행중인 프로세스에 적용되고 있는 limits 내용을 표시한다.

ulimit 등을 통해 확인되는 limits 정보는 앞으로 실행될 프로세스에 대한 limit 정보만을 표시해주기 때문에, 현재 동작중인 프로세스의 정확한 limit 를 확인하기 위해서는 이 파일을 참조하면 된다.

$ cat /proc/3340/limits 
Limit                     Soft Limit           Hard Limit           Units     
Max cpu time              unlimited            unlimited            seconds   
Max file size             unlimited            unlimited            bytes     
Max data size             unlimited            unlimited            bytes     
Max stack size            8388608              unlimited            bytes     
Max core file size        unlimited            unlimited            bytes     
Max resident set          unlimited            unlimited            bytes     
Max processes             61452                61452                processes 
Max open files            1024                 4096                 files     
Max locked memory         65536                65536                bytes     
Max address space         unlimited            unlimited            bytes     
Max file locks            unlimited            unlimited            locks     
Max pending signals       61452                61452                signals   
Max msgqueue size         819200               819200               bytes     
Max nice priority         0                    0                    
Max realtime priority     0                    0                    
Max realtime timeout      unlimited            unlimited            us        

Reference

<references />