由于某些原因,我无法从 task_for_pid() 中得到任何信息相同的(操作系统/内核)失败错误。
#include <stdio.h>
#include <mach/mach_traps.h>
#include <mach/mach_init.h>
int main(int argc, char* argv[])
{
mach_port_name_t task;
printf("%d\n", argv[1]);
int pid = atoi(argv[1]);
printf("%d\n%d\n", pid, current_task());
int error = task_for_pid(2055, 24269, &task);
printf("%x\n", task);
if (error)
{
printf("task_for_pid return error:\n %s\n", mach_error_string(error));
} else {
printf("Get the process %d's task port : %x\n", pid, task);
}
return 0;
}
输出如下所示:
gcc -o test test.c;./test 24269
803206115
24269
2055
0
task_for_pid return error:
(os/kern) failure
关于我为什么没有得到任务的任何想法?我以root身份运行它。
正如亚当罗森菲尔德所说,它确实在标题中说它已经过时了,但如果那是真的,我还能用旧版本的工具链编译和运行它吗?或者它被什么取代了?有人知道吗?