您可以查看/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
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
从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.
Run Code Online (Sandbox Code Playgroud)