http://stackoverflow.com/questions/3596781/detect-if-gdb-is-running

There's some code there - basically the way it works is that you try to ptrace_attach to it (as if you were the debugger), and if it's already being debugged, that attach will fail - if it fails, gdb (or another debugger) is running (or it has anti-debugger measurements in place, e.g. disallows ptrace at all). If it succeeds, you need to tell it to continue and detach, at which point the process can be killed.