3

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.

Alexander Mills
  • 9,330
  • 19
  • 95
  • 180

1 Answers1

3

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).

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164