Virtual-Memory
如何知道兩個程序之間的共享記憶體?
我需要知道兩個程序之間共享的記憶體量,即它們共享記憶體的交集。
有任何想法嗎?
您可以查看
/proc/<pid>/maps, /proc/<pid>/smaps
(或者pmap -x <pid>
如果您的作業系統支持)感興趣的程序 ID 並比較輸出以確定共享記憶體區域。這包括通過 shmget 呼叫的共享記憶體段,以及任何共享庫、文件。編輯:正如 mr.spuratic 指出的,他的答案在這裡有更多關於核心方面的細節
您可以使用 ps 查看程序 RSS,但它不會考慮所有共享頁面。要查看特定過程的 RSS,請參見下文
cv@thunder:~$ ps -o rss,pid,comm -p $$,7023 RSS PID COMMAND 22060 7023 xfwm4 6876 18094 bash
smem
考慮到共享頁面,該工具提供了更詳細的資訊。有關上述相同過程,請參見下面的輸出cv@thunder:~$ smem -t |egrep "RSS|$$|7023" PID User Command Swap USS PSS RSS 9852 cv grep -E RSS|18094|7023 0 340 367 2220 18094 cv bash 0 3472 4043 6876 7023 cv xfwm4 --display :0.0 --sm-c 0 5176 7027 22192
來自
man smem
:smem reports physical memory usage, taking shared memory pages into account. Unshared memory is reported as the USS (Unique Set Size). Shared memory is divided evenly among the processes sharing that memory. The unshared memory (USS) plus a process's proportion of shared memory is reported as the PSS (Proportional Set Size). The USS and PSS only include physical memory usage. They do not include memory that has been swapped out to disk.