Re: task_for_pid never returns KERN_SUCCESS, any ideas?
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:cc:message-id:from:to :in-reply-to:content-type:content-transfer-encoding:mime-version :subject:date:references:x-mailer; bh=DZLh5n7P+4uFcNpQlhO4yVXjcTg6l327OpeDWUk8KMw=; b=FL6G1mxROs1h8zHiP1k9mfM6G6KbF+9SXszGB9QwTANlCRvm5DsOpXMvd2fDtz6UOM KVgkT2xUvENtov6BJnNY9/H7Ehy6z+foxU2O9VWN0nbUOLaYgKUcfmphEzAyHNov/WoB 3vtgfWwZI4xl/C6dEOGKF+x/lTXcyadIkekfE= Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=cc:message-id:from:to:in-reply-to:content-type :content-transfer-encoding:mime-version:subject:date:references :x-mailer; b=o9B5CGo/owA9iUX87Gu7kywbE5meEYvO9Qnr2nOdAkmik/wVQnipoeEVm2hOyHmgb3 GxalkBx9r0KRLSDGr7ywyIVX67dzdjyxSGDnv20mw4p4M+M+unH4KY3sUMFTd+PBKd/5 svGSLK8vArEbsRXZgGguelV3nWXt4CN2NZ9vk= On Jan 12, 2009, at 13:37 , Gary Fung 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 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. 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. Jason Jason Coco wrote: 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). 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? No, it was deemed a security risk in one of the patches to tiger (close to the release of leopard), and since that patch, you have to have privileges to execute task_for_pid(), even for tasks owned by the same user as the process. If the process is in the procmod or procview group, it may be given access, or if it has the system.privilege.taskport right, it will be given access. See taskgated(8) for more information. And yes, unfortunately 5 is just the general KERN_FAILURE, but it's still good practice :) Is there an easier way to retrieve the memory usage of a process? Retrieving the pid and process name was not this difficult. It is difficult because once you have the task port right, you can inject anything into that task that you feel like. For instance, you can start a new thread that the process knows nothing about and inject it directly into the running process. _______________________________________________ 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... This email sent to site_archiver@lists.apple.com
participants (1)
-
Jason Coco