Created
March 30, 2010 12:39
-
-
Save torsten/349064 to your computer and use it in GitHub Desktop.
Detecting an attached gdb on Mac OS X
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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