在 C 中的 darwin 上,task_for_pid 总是返回(os/kern)失败
由于某些原因,我无法从 task_for_pid() 中得到任何结果 我找不到太多信息,但我试图将其附加到另一个进程并搜索其内存,但每次我尝试使用 task_for_pid 时,都会得到相同的 (os/kern) 失败错误。
#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 身份运行它。
正如 Adam Rosenfield 所说,它确实在标头中指出它已过时,但如果这是真的,我仍然可以使用旧版本的工具链来编译和运行它吗?或者它被什么取代了?有人知道吗?
For some reasons I cannot get anything to come out of task_for_pid()
I can't find very much information but what I am trying to do it attach to another process and search its memory, but every time I try to use task_for_pid, I get the same (os/kern) failure error.
#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;
}
Output looks like:
gcc -o test test.c;./test 24269
803206115
24269
2055
0
task_for_pid return error:
(os/kern) failure
Any idea's as to why im not getting a task, ever?
I am running it as root.
As Adam Rosenfield said, it does say in the header that it is obsolete, but if thats true, could I still compile and run it with an older version of the toolchain? or what has it been replaced with? does anyone know?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在 Mac OS X 10.6.8 上使用任何正在运行的进程运行此代码(使用 sudo)都没有问题:
例如,这是我的 pid 182 (Dock) 结果
I have no problem running this code (with sudo) on Mac OS X 10.6.8 with any running process:
For example, here is my result with pid 182 (Dock)