何らかの理由で、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
なぜ私がタスクを取得しないのかについて何か考えはありますか? ルートとして実行しています。
Adam Rosenfield が言ったように、ヘッダーには廃止されたと書かれていますが、それが本当なら、古いバージョンのツールチェーンでコンパイルして実行できますか? またはそれは何に置き換えられましたか?誰か知っていますか?