I want to fetch the memory consumed by each process in OSX. I have tried to call below function but "proc_pidinfo" call is getting failed for some of the processes. It returns value 0 when it fails.
int main(int argc, char **argv)
{
if(argc != 2) {
puts("Usage: process_detail <pid>");
return 1;
}
struct proc_taskallinfo info;
int ret = proc_pidinfo(atoi(argv[1]), PROC_PIDTASKALLINFO, 0, (user_addr_t) &info, sizeof(struct proc_taskallinfo));
printf("ret=%d, result=%s, rss memory: %lld\n", ret, (char *) info.pbsd.pbi_comm, info.ptinfo.pti_resident_size);
return 0;
}
May i know why "proc_pidinfo" is getting failed for some of the pids. ? Can i implement any other way ?
Thank you in advance.