Skip to content

Commit

Permalink
fix: ignore zombie processes
Browse files Browse the repository at this point in the history
  • Loading branch information
lwouis committed Aug 27, 2020
1 parent 023561d commit 50c8c82
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/api-wrappers/HelperExtensions.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Cocoa
import Darwin

extension Collection {
// recursive flatMap
Expand Down Expand Up @@ -172,3 +173,16 @@ extension NSImage {
return dimmed
}
}

extension pid_t {
func isZombie() -> Bool {
var kinfo = kinfo_proc()
var size = MemoryLayout<kinfo_proc>.stride
var mib: [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, self]
sysctl(&mib, u_int(mib.count), &kinfo, &size, nil, 0)
let command = withUnsafePointer(to: &kinfo.kp_proc.p_comm) {
String(cString: UnsafeRawPointer($0).assumingMemoryBound(to: CChar.self))
}
return kinfo.kp_proc.p_stat == SZOMB
}
}
2 changes: 1 addition & 1 deletion src/logic/Applications.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Applications {
}

private static func isActualApplication(_ app: NSRunningApplication) -> Bool {
return app.activationPolicy != .prohibited || isNotXpc(app)
return (app.activationPolicy != .prohibited || isNotXpc(app)) && !app.processIdentifier.isZombie()
}

private static func isNotXpc(_ app: NSRunningApplication) -> Bool {
Expand Down

0 comments on commit 50c8c82

Please sign in to comment.