What is the relationship between ptrace and waitpid?

Viewed 58

I am practicing using ptrace but I don’t know much about the relationship between it and waitpid.

This is my test program:

int main(int argc, char *argv[])
{
    pid_t pid = 22092;
    if (ptrace(PTRACE_ATTACH, pid, NULL, NULL) == -1) {
        perror("PTRACE_ATTACH");
        return 1;
    } 
    
    //waitpid(pid, NULL, WUNTRACED);
     
    if (ptrace(PTRACE_DETACH, pid, NULL, NULL) == -1) {
        perror("PTRACE_DETACH");
        return 1;
    }
    
    return 0;
}

If I mark waitpid(pid, NULL, WUNTRACED), there will be (no such process) problem, but if waitpid is added, it can be executed normally. I want to ask what causes it.

0 Answers
Related