Tools like ps and pgrep can help you learn about the processes running on your system. Sometimes, the next step in getting a report on processes is exploring a single process' memory map. You can use the pmap command for that.
[Cheat sheet: Old Linux commands and their modern replacements ]
Check a process
Suppose you need to know how the sshd process is mapped in memory. First, find the process ID (PID) of the process:
$ ps aux | grep sshd
root 5484 [...] sshd: /usr/sbin/sshd -D [listener]
0 of 10-100 startups
Use the PID 5484 to explore the process:
$ sudo pmap 5484 | more
5484: sshd: /usr/sbin/sshd -D [listener]
0000560d6317f000 48K r---- sshd
0000560d6318b000 564K r-x-- sshd
0000560d63218000 296K r---- sshd
0000560d63262000 16K r---- sshd
0000560d63266000 4K rw--- sshd
0000560d63267000 16K rw--- [ anon ]
0000560d6502c000 504K rw--- [ anon ]
00007f929fcc8000 12K rw--- [ anon ]
00007f929fccb000 16K r---- libgpg-error.so
00007f929fccf000 88K r-x-- libgpg-error.so
00007f929fce5000 40K r---- libgpg-error.so
00007f929fcef000 4K r---- libgpg-error.so
00007f929fcf0000 4K rw--- libgpg-error.so
[...]
00007ffd61ce8000 132K rw--- [ stack ]
00007ffd61d92000 16K r---- [ anon ]
00007ffd61d96000 8K r-x-- [ anon ]
ffffffffff600000 4K --x-- [ anon ]
total: 15612K
The pmap output reports the process' memory usage, including all the components it uses, such as libraries and binary files. The columns include the memory address, offset, permission, and name.
[ No-cost online course: Red Hat Enterprise Linux technical overview. ]
You can run the same command with the -x flag to get even more detailed output:
Address Kbytes RSS Dirty Mode Mapping
0000560d6317f000 48 48 0 r---- sshd
0000560d6318b000 564 500 0 r-x-- sshd
0000560d63218000 296 160 0 r---- sshd
0000560d63262000 16 16 16 r---- sshd
0000560d63266000 4 4 4 rw--- sshd
0000560d63267000 16 16 16 rw--- [ anon ]
Here's what that information means:
- Address: The beginning memory address allocation
- Kbytes: Memory allocation in kilobytes
- RSS: Resident set size of the process in memory
- Dirty: The status of the memory pages
- Mode: Access mode and privileges
- Mapping: The user-facing name of the application or library
[ Find out what sysadmins need to know about Linux permissions ]
In this case, the binary sshd is allocated 48 kilobytes from the memory address 0000560d6317f000 to the address 0000560d6317f000. You can test whether this is true using a Python shell. First, subtract the memory address to get the offset. The result is returned in hex:
$ python
Python 3.10.7
>>> hex ( 0x0000560d6318b000 -0x0000560d6317f000 );
'0xc000'
Convert the hex value:
>>> int (hex ( 0x0000560d6318b000 -0x0000560d6317f000 ),16);
49152
Finally, divide this result by 1024:
>>> 49152/1024
48
The result is 48 kilobytes.
Mapping with pmap
The pmap utility gathers most of its information from the /proc/PID/smaps file and makes it friendly to humans. The [ anon ] value is anonymous memory mapping, which is part of the memory populated with data not taken from the filesystem but allocated when needed.
You can use pmap to monitor the movement of memory across a particular time range. You can also use it to analyze a memory value that always increases and never decreases or to locate the culprit of a memory leak.
This example is a brief overview of what's possible to learn about a single process. Use it well.
[ For more tips on Linux administration, read How to use the lsof command to troubleshoot Linux. ]
저자 소개
Giancarlo del Rossi, is a Software Maintenance Engineer at Red Hat. He has over 30 years of experience in the Information Technology environment and most of those years in Linux. Specialized in system administration and security, he is currently interested in C language programming and interaction with the Linux Kernel. In his spare time, he trains in the gym and enjoys wood working as a hobby.
채널별 검색
오토메이션
기술, 팀, 인프라를 위한 IT 자동화 최신 동향
인공지능
고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트
오픈 하이브리드 클라우드
하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요
보안
환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보
엣지 컴퓨팅
엣지에서의 운영을 단순화하는 플랫폼 업데이트
인프라
세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보
애플리케이션
복잡한 애플리케이션에 대한 솔루션 더 보기
가상화
온프레미스와 클라우드 환경에서 워크로드를 유연하게 운영하기 위한 엔터프라이즈 가상화의 미래