Skip to content

Instantly share code, notes, and snippets.

@dermotos
Last active March 5, 2018 03:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dermotos/fde82d3eb617f5085b22893166519d51 to your computer and use it in GitHub Desktop.
Save dermotos/fde82d3eb617f5085b22893166519d51 to your computer and use it in GitHub Desktop.
Swift computed variable that lets you know if a debugger is currently attached to the process
class Utlity {
internal var isDebuggerAttached: Bool {
var info = kinfo_proc()
var mib : [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()]
var size = MemoryLayout<kinfo_proc>.stride
let junk = sysctl(&mib, UInt32(mib.count), &info, &size, nil, 0)
assert(junk == 0, "sysctl failed")
return (info.kp_proc.p_flag & P_TRACED) != 0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment