2

在命令行中,我可以使用vmmap -v -purge 50554查找进程 50554 的内存信息,并得到如下输出:

                                  VIRTUAL RESIDENT    DIRTY  SWAPPED VOLATILE   NONVOL    EMPTY   REGION 
REGION TYPE                          SIZE     SIZE     SIZE     SIZE     SIZE     SIZE     SIZE    COUNT (non-coalesced) 
===========                       ======= ========    =====  ======= ========   ======    =====  ======= 
Accelerate.framework                 256K     256K     256K       0K       0K     256K       0K        3 
Activity Tracing                    2048K      40K      40K       0K       0K       0K       0K        2 

......
                                          VIRTUAL   RESIDENT      DIRTY    SWAPPED ALLOCATION      BYTES          REGION
MALLOC ZONE                                  SIZE       SIZE       SIZE       SIZE      COUNT  ALLOCATED  % FULL   COUNT
===========                               =======  =========  =========  =========  =========  =========  ======  ======
DefaultMallocZone_0x10453d000              532.5M     524.4M     476.8M         0K    3203739     424.3M     79%     829
DefaultPurgeableMallocZone_0x117c92000      14.2M      13.7M      13.7M         0K          3      14.2M     99%       4
WebKit Malloc_0x7fff7c65ecb8                12.0M      8928K      8756K         0K          3      12.0M    100%       3
QuartzCore_0x7fc9519bc000                   1516K      1516K      1516K         0K      27313      1390K     91%     207
unnamed_zone_0x120a0a000                    1024K        12K        12K         0K          4        224      0%       2
x-alloc_0x7fc95189ec00                        12K        12K        12K         0K         48       1696     13%       1
x-alloc_0x7fc951047800                         8K         8K         8K         0K          4        448      5%       1
GFXMallocZone_0x10598d000                      0K         0K         0K         0K          0         0K               0
===========                               =======  =========  =========  =========  =========  =========  ======  ======
TOTAL                                      561.1M     548.3M     500.5M         0K    3231114     451.8M     80%    1047

但是有没有我可以调用实现相同功能的 API?

4

1 回答 1

2

您的问题的答案有些复杂,但可以在 mach_vm_region_info() 的内核源代码中找到:https ://opensource.apple.com/source/xnu/xnu-201/osfmk/vm/vm_debug.c

此代码(除其他外)通过 VM 映射表运行并构建结构的链接列表,其中包含 vmmap(1) 命令显示的所有信息。

于 2017-08-15T18:11:56.650 回答