简体   繁体   中英

Identify stack and heap segments in macOS current process

I'd like to add memory profiler to my daemon which runs under macOS. In linux, i could simply check the /proc/<pid>/map for any mapped memory in the process, and look for pathname = [heap] or pathname = [stack].

Is there any alternative mac syscall/MIG/mach message for that purpose ?

I've tried to see if proc_pidinfo contain any valuable information, but unfortunately nothing related to my needs.

Notice that apple provide such tool for other remote processes called vmmap and it doesn't provide any api at all (it's merely command-line tool) and there's no public API for this demand, but perhaps there's an API to extract this information from "within" the process itself.

I don't know what public APIs (if any) it uses, but the closest equivalent to Linux's /proc/$pid/maps in macOS is the vmmap utility. Running it with a PID as an argument will give you a detailed report on all regions mapped by the process, including some interesting details on memory usage within malloc zones.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM