Skip to content

Instantly share code, notes, and snippets.

@torsten
Created March 30, 2010 12:39
Show Gist options
  • Save torsten/349064 to your computer and use it in GitHub Desktop.
Save torsten/349064 to your computer and use it in GitHub Desktop.
Detecting an attached gdb on Mac OS X
#include <sys/sysctl.h>
#include <unistd.h>
#include <err.h>
#include <errno.h>
#include <stdio.h>
int main()
{
int mib[4];
size_t bufSize = 0;
int localError = 0;
struct kinfo_proc kinfoProc;
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_PID;
mib[3] = getpid();
bufSize = sizeof(kinfoProc);
localError = sysctl(mib, 4, &kinfoProc, &bufSize, NULL, 0);
if(localError < 0)
{
perror("Failure calling sysctl");
return 0;
}
if(kinfoProc.kp_proc.p_flag & P_TRACED)
printf("I am traced\n");
else
printf("I am not traced\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment