pmap command
linux의 pmap 명령어를 통해 프로세스의 메모리 맵을 볼 수 있습니다.
기본 사용법
$> pmap -x 3273049
3273049: /opt/java/bin/java -Djava.util.logging.config.file=/opt/apache-tomcat-8.5.24/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -XX:+UseZGC -XX:ConcGCThreads=4 -XX:NativeMemoryTracking=detail
Address Kbytes RSS Dirty Mode Mapping
0000000800000000 11932 11868 3728 rw--- classes_nocoops.jsa
0000000800ba7000 356 0 0 ----- [ anon ]
0000000800c00000 128 128 128 rw--- [ anon ]
0000000800c20000 128 128 128 rw--- [ anon ]
...
응용
프로세스 이름을 통해서 메모리 맵 확인하려면 grep 명령어와 awk 명령어를 사용합니다.
$> pmap -x $(ps -ef | grep tomcat-8.5.24 | grep java | awk '{print $2}')
...
내용이 길어져서 특정 칼럼(여기선 RSS) 값을 기준으로 정렬하여 보고 싶을 때는 sort 명령어를 이용합니다.
$> pmap -x $(ps -ef | grep -E apache-tomcat-8.5.24 | grep java | awk '{print $2}') | sort -k 3 -n -r | more
total kB 317634916 3202884 3161320
0000100000000000 6291456 2332508 2332508 rw-s- memfd:java_heap (deleted)
0000080000000000 6291456 281320 281320 rw-s- memfd:java_heap (deleted)
0000040000000000 6291456 255792 255792 rw-s- memfd:java_heap (deleted)
00007fb690000000 37712 26576 26576 rw--- [ anon ]
...
help pmap
$> pmap --help
Usage:
pmap [options] PID [PID ...]
Options:
-x, --extended show details
-X show even more details
WARNING: format changes according to /proc/PID/smaps
-XX show everything the kernel provides
-c, --read-rc read the default rc
-C, --read-rc-from=<file> read the rc from file
-n, --create-rc create new default rc
-N, --create-rc-to=<file> create new rc to file
NOTE: pid arguments are not allowed with -n, -N
-d, --device show the device format
-q, --quiet do not display header and footer
-p, --show-path show path in the mapping
-A, --range=<low>[,<high>] limit results to the given range
-h, --help display this help and exit
-V, --version output version information and exit
For more details see pmap(1).
TLDR
$> tldr pmap
pmap
Report memory map of a process or processes.
More information: https://manned.org/pmap.
- Print memory map for a specific process id (PID):
pmap pid
- Show the extended format:
pmap --extended pid
- Show the device format:
pmap --device pid
- Limit results to a memory address range specified by `low` and `high`:
pmap --range low,high
- Print memory maps for multiple processes:
pmap pid1 pid2 ...