I have this simple C program on MacOS:

#include <stdlib.h>
#include <sys/wait.h>
#include <stdio.h>
#include <sys/ptrace.h>

int main(int argc, char *argv[]) {
    pid_t pid = atoi(argv[1]);
    printf("pid = %jd\n", (intmax_t) pid);
    return ptrace(PT_ATTACHEXC, pid, 0, 0);

when I compile with gcc / cc, I get this error:

In file included from my-waiter.c:4:
/usr/include/sys/ptrace.h:99:38: error: unknown type name 'caddr_t'
int     ptrace(int _request, pid_t _pid, caddr_t _addr, int _data);
1 error generated.

does anyone know how to use ptrace() on OSX? I can't figure out how to get this to compile.


As indicated by user4556274, you need to #include <sys/types.h> before you #include <sys/ptrace.h> (see your local ptrace(3) manpage for details).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.