File tree Expand file tree Collapse file tree
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}
Original file line number Diff line number Diff line change @@ -426,10 +426,6 @@ private final class CodexRPCClient: @unchecked Sendable {
426426 Self . log. debug ( " Codex RPC stopping " )
427427 self . process. terminate ( )
428428 }
429- if let registryToken = self . registryToken {
430- ProcessRegistry . shared. unregister ( registryToken)
431- self . registryToken = nil
432- }
433429 }
434430
435431 // MARK: - JSON-RPC helpers
You can’t perform that action at this time.
0 commit comments