#include <assert.h>
#include <stdbool.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/sysctl.h>

static bool AmIBeingDebugged(void)
// Returns true if the current process is being debugged (either
// running under the debugger or has a debugger attached post facto).
{
int junk;
int mib[4];
struct kinfo_proc info;
size_t size;

// Initialize the flags so that, if sysctl fails for some bizarre
// reason, we get a predictable result.

info.kp_proc.p_flag = 0;

// Initialize mib, which tells sysctl the info we want, in this case
// we're looking for information about a specific process ID.

mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_PID;
mib[3] = getpid();

// Call sysctl.

size = sizeof(info);
junk = sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0);
assert(junk == 0);

// We're being debugged if the P_TRACED flag is set.

return ( (info.kp_proc.p_flag & P_TRACED) != 0 );
}

  1. Important: Because the definition of the kinfo_proc structure (in <sys/sysctl.h>) is conditionalized by __APPLE_API_UNSTABLE, you should restrict use of the above code to the debug build of your program.
 

How do I determine if I'm being run under the debugger?的更多相关文章

  1. Could not determine which “make” command to run. Check the “make” step in the build configuration

    环境: QT5.10 VisualStudio2015 错误1: Could not determine which “make” command to run. Check the “make” s ...

  2. SH Script Grammar

    http://linux.about.com/library/cmd/blcmdl1_sh.htm http://pubs.opengroup.org/onlinepubs/9699919799/ut ...

  3. allpaths 使用

    软件下载与说明:http://www.broadinstitute.org/software/allpaths-lg/blog/?page_id=12 原始数据的深度要达到100以上. 至少要两个库, ...

  4. Python定时调度--多任务同一时间开始跑 scheduler.enterabs

    Event Priorities If more than one event is scheduled for the same time their priority values are use ...

  5. JUnit扩展:引入新注解Annotation

    发现问题 JUnit提供了Test Suite来帮助我们组织case,还提供了Category来帮助我们来给建立大的Test Set,比如BAT,MAT, Full Testing. 那么什么情况下, ...

  6. 为什么这么多Python框架

    原文:http://bitworking.org/news/Why_so_many_Python_web_frameworks BitWorking This is Joe Gregorio's wr ...

  7. IOS高级开发~开机启动&无限后台运行&监听进程

    一般来说, IOS很少给App后台运行的权限. 仅有的方式就是 VoIP. IOS少有的为VoIP应用提供了后台socket连接,定期唤醒并且随开机启动的权限.而这些就是IOS上实现VoIP App的 ...

  8. HPUX 11.31 MC-SG SGeRAC配置

    HPUX 11.31 MC-SG SGeRAC配置 环境: 系统版本号 hp-unix 11.3v2 1503 serviceguard extension版本号 T1907 实施 1. 磁盘空间划分 ...

  9. RMAN命令DELETE操作总结

    本篇总结一下RMAN命令中的DELETE操作,DELETE命令用于删除RMAN备份记录以及相应的物理文件. To delete physical backups and copies as well ...

随机推荐

  1. 使用 Lombok 简化项目中无谓的Java代码

    在写使用Java时,难免会有一些模板代码要写,不然get/set,toString, hashCode, close 资源,定义构造函数等等.代码会显得很冗余,很长.Lombok项目可以是我们摆脱这些 ...

  2. Linux学习系列之Nginx调优实战

    Nginx配置文件性能微调 全局的配置 user www-data; pid /var/run/nginx.pid; worker_processes auto; worker_rlimit_nofi ...

  3. Jython:java调用python文件之第三方包路径问题

    本文转载自:http://blog.csdn.net/ztf312/article/details/51338060 本方法解决python代码的可移植性,不需要在新机器上配置python环境,只通过 ...

  4. HDU 1969 Pie(二分,注意精度)

    Pie Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  5. PAT 甲级 1010 Radix (25)(25 分)进制匹配(听说要用二分,历经坎坷,终于AC)

    1010 Radix (25)(25 分) Given a pair of positive integers, for example, 6 and 110, can this equation 6 ...

  6. TCL列表

    列表是Tcl的基本可用数据类型之一.它是用于表示项目的有序集合.它可以包括不同类型的在同一列表的项目.此外,一个列表可以包含另一个列表. 需要注意的一个重要的事情是,列表表示为完全串并处理在需要时,形 ...

  7. C++实现大正整数及其相关运算(长期更新)

    /** 只考虑正数[1, +∞); “-”运算只允许大数减小数; 小端存储: */ typedef struct BigInteger0 { vector<int> v; BigInteg ...

  8. 安装 ORACLE 11G出现Error Message:PRVF-7535

    Error Message:PRVF-7535 : Proper architectureis not found on node "tsing" [Expected = &quo ...

  9. ubuntu ufw防火墙

    由于LInux原始的防火墙工具iptables过于繁琐,所以ubuntu默认提供了一个基于iptable之上的防火墙工具ufw. ubuntu 9.10默认的便是UFW防火墙,它已经支持界面操作了.在 ...

  10. 24.Swap Nodes in Pairs (List; Two-Pointers)

    Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2-&g ...