Skip to content

Instantly share code, notes, and snippets.

@bewebste
Created August 13, 2013 22:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bewebste/6226400 to your computer and use it in GitHub Desktop.
Save bewebste/6226400 to your computer and use it in GitHub Desktop.
Function to tell whether a debugger is attached
BOOL BWProcessIsBeingTraced()
{
int mib[4];
size_t bufSize = 0;
struct kinfo_proc kp;
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_PID;
mib[3] = getpid();
bufSize = sizeof (kp);
if (sysctl(mib, 4, &kp, &bufSize, NULL, 0) < 0)
{
return 0;
}
return ((kp.kp_proc.p_flag & P_TRACED) != 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment