Re: task_for_pid never returns KERN_SUCCESS, any ideas?
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com Le 12 janv. 09 à 20:23, Gary Fung a écrit : Le 12 janv. 09 à 19:37, Gary Fung a écrit : Jason Coco wrote: On Jan 12, 2009, at 12:54 , Gary Fung wrote: Tried to retrieve task_info_t by using task_for_pid but the following code does not equate to true Jason It returns 5 for all pids, which is a KERN_FAILURE correct? This doesn't provide much information at all. It only returns KERN_SUCCESS for the running process itself. I thought you have permission to retrieve task_info for other processes under the same user? It was until Mac OS 10.4 Intel version and Mac OS 10.5 for PPC and Intel (IIRC) Is there an easier way to retrieve the memory usage of a process? Retrieving the pid and process name was not this difficult. I think you can get some value about memory usage usign sysctl to retreive the distant kproc_info struct. _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... Jean-Daniel Dupas wrote: task_t task = MACH_PORT_NULL; struct task_basic_info tinf; if(task_for_pid(mach_task_self(), pid, &task) == KERN_SUCCESS) { ... //not reached } mach_task_self returns non null value so that should be ok. But task_for_pid does not return anything for &task. Any ideas? I've iterated through all the pids currently running, same result. Ran it on Leopard. task_for_pid() requires special privileges to execute. Instead of testing for KERN_SUCCESS in the future, I suggest using a variable to test, then you can see exactly what failed (in this case, you will not have privileges to execute it). The easiest way to deal with this (although, probably not the best way) is to execute the application as root. You can see the man page for taskgated(8) for more information on task_for_pid() and its security issues. Did I miss something obvious? I only found p_comm (name) and pid. But I'm not familiar with kproc_info at all, so maybe some hints on how to retrieve memory usage? Sorry for the typo, I mean kinfo_proc (see man sysctlbyname). But after a check, I didn't find a memory usage field in the struct. So that is probably a wrong way. This email sent to site_archiver@lists.apple.com
participants (1)
-
Jean-Daniel Dupas