#include #include #include #include #include #include #include /* 174 kamil@chieftec /tmp $ gcc isdebugged.c 175 kamil@chieftec /tmp $ ./a.out traced=FALSE 176 kamil@chieftec /tmp $ gdb ./a.out GNU gdb (GDB) 8.0.1 Copyright (C) 2017 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64--netbsd". Type "show configuration" for configuration details. For bug reporting instructions, please see: . Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from ./a.out...(no debugging symbols found)...done. (gdb) r Starting program: /tmp/a.out [New LWP 1 of process 6373] traced=TRUE [Inferior 1 (process 6373) exited normally] (gdb) q */ int main(int argc, char **argv) { struct kinfo_proc2 p; size_t len = sizeof(p); int name[] = { [0] = CTL_KERN, [1] = KERN_PROC2, [2] = KERN_PROC_PID, [3] = getpid(), [4] = (int)(sizeof(struct kinfo_proc2)), [5] = 1 }; const size_t namelen = __arraycount(name); if (sysctl(name, namelen, &p, &len, NULL, 0) == -1) err(EXIT_FAILURE, "sysctl"); printf("traced=%s\n", p.p_flag & P_TRACED ? "TRUE" : "FALSE"); return 0; }