Hi, all,
Is task_for_pid still supported on Leopard 10.5.3(9D34)? I found when I call this function it will always return dsChkErr( code 5). Following my simple test program, use gcc test.c -o test -framework carbon to compile and ./test pid to run.
#include <sys/sysctl.h> #include <mach-o/dyld.h> #include <mach/mach_traps.h> #include <mach/mach_init.h> #include <mach/message.h> #include <mach/vm_map.h> #include <mach/vm_region.h> #include <mach/mach_port.h> #include <mach-o/fat.h> #include <mach-o/nlist.h> #include <Carbon/Carbon.h>
int main(int argc, char* argv[]) { mach_port_name_t task; int pid = atoi(argv[1]); int error = task_for_pid((mach_port_name_t)task_self_trap(), pid,(mach_port_name_t *) &task); if (error) { printf("task_for_pid return error %d : %s\n", error, GetMacOSStatusErrorString(error)); } else { printf("Get the process %d's task port : %x\n", pid, task); } return 0; } |