File tree Expand file tree Collapse file tree
Sources/CodexBarCore/Host/Process Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import Foundation
2+ #if canImport(Darwin)
3+ import Darwin
4+ #else
5+ import Glibc
6+ #endif
27
38public final class ProcessRegistry : @unchecked Sendable {
49 public static let shared = ProcessRegistry ( )
@@ -35,12 +40,32 @@ public final class ProcessRegistry: @unchecked Sendable {
3540 self . lock. unlock ( )
3641
3742 for entry in active {
43+ let pid = entry. process. processIdentifier
3844 if entry. process. isRunning {
3945 entry. process. terminate ( )
4046 }
41- if let pgid = entry. processGroup {
47+
48+ if let pgid = entry. processGroup,
49+ pgid > 0 ,
50+ getpgid ( pid) == pgid
51+ {
4252 kill ( - pgid, SIGTERM)
4353 }
54+
55+ let waitDeadline = Date ( ) . addingTimeInterval ( 1.0 )
56+ while entry. process. isRunning, Date ( ) < waitDeadline {
57+ usleep ( 100_000 )
58+ }
59+
60+ if entry. process. isRunning {
61+ if let pgid = entry. processGroup,
62+ pgid > 0 ,
63+ getpgid ( pid) == pgid
64+ {
65+ kill ( - pgid, SIGKILL)
66+ }
67+ kill ( pid, SIGKILL)
68+ }
4469 }
4570 }
4671}
You can’t perform that action at this time.
0 commit comments