【发布时间】:2013-12-04 02:23:08
【问题描述】:
int Enable ( int pid)
{
int status;
#if 1
{
printf ( "child pid = %d \n", pid );
long ret = ptrace (PTRACE_ATTACH, pid, NULL, NULL);
do {
int w = waitpid(-1, &status, 0);
if (w == -1) {
perror("waitpid error :");
exit(EXIT_FAILURE);
}
if (WIFEXITED(status)) {
printf("exited, status=%d\n", WEXITSTATUS(status));
} else if (WIFSIGNALED(status)) {
printf("killed by signal %d\n", WTERMSIG(status));
} else if (WIFSTOPPED(status)) {
printf("stopped by signal %d\n", WSTOPSIG(status));
} else if (WIFCONTINUED(status)) {
printf("continued\n");
}
} while (!WIFEXITED(status) && !WIFSIGNALED(status));
exit(EXIT_SUCCESS);
}
#endif
// while ((result = wait(&status)) != -1 && result != pid){ printf (" this is not my child go back \n"); };
}
int main(int arg, char*argv[])
{
Enable(atoi(argv[1]));
sleep(125);
}
-- 我运行了一个 pid 为 6841 的守护进程,并尝试在 ptrace-attach 之后等待它
./ptrace 6841
child pid = 6841
waitpid error :: No child processes
简而言之,我希望能够等待非子进程 - 欢迎任何其他程序。
【问题讨论】:
-
你不检查
ptrace是否返回错误。 -
这表明
ptrace()失败了。检查errno找出原因。 -
工作。 :) 我有些权限问题谢谢。
-
哎呀。如果我不是 root 则无法工作:)