17#define WIN32_LEAN_AND_MEAN
22#include <sys/sysctl.h>
34 return IsDebuggerPresent();
39 struct kinfo_proc info;
45 info.kp_proc.p_flag = 0;
52 mib[2] = KERN_PROC_PID;
58 junk = sysctl(mib,
sizeof(mib) /
sizeof(*mib), &info, &
size,
nullptr, 0);
63 return ((info.kp_proc.p_flag & P_TRACED) != 0);
66 int fd = open(
"/proc/self/status", O_RDONLY);
69 int size = read(fd, buf,
sizeof(buf) - 1);
73 assert(
size <
int(
sizeof(buf)) - 1);
74 buf[
sizeof(buf) - 1] =
'\0';
76 const char*
pos = strstr(buf,
"TracerPid:");
79 pos += strlen(
"TracerPid:");
80 while (*
pos !=
'\n' && isspace(*
pos))
82 return *
pos !=
'\n' && *
pos !=
'0';
bool isDebuggerAttached()
Returns true if the process is running with a debugger attached.