首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ptrace/等待非子对象

Ptrace/等待非子对象
EN

Stack Overflow用户
提问于 2013-12-04 10:23:09
回答 2查看 1.5K关注 0票数 0
代码语言:javascript
复制
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后尝试等待它

代码语言:javascript
复制
./ptrace 6841
child pid = 6841 
waitpid error :: No child processes

简而言之,我希望能够等待一个非子进程--任何其他受欢迎的程序。

EN

回答 2

Stack Overflow用户

发布于 2017-01-10 21:18:05

oops。如果我不是root用户,则无法工作:)

这是记录在案的行为;参见ptrace() - Unix, Linux System Call,例如。

非根进程无法跟踪它们无法向

发送信号的进程

票数 0
EN

Stack Overflow用户

发布于 2016-03-03 17:02:42

代码语言:javascript
复制
if(ret == 0)
{
    //child process
}
else
{
    //parent process
}
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20365656

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档