Files
luma/Sources/LumaCore/VirtualMachines/GuestProcess.swift
Ole André Vadla Ravnås f89d31aa9d core: Order OS checks Windows, macOS, Linux
The house order was not kept where these were first written.
2026-09-17 13:15:53 +02:00

31 lines
807 B
Swift

import Foundation
#if os(Windows) || os(macOS) || os(Linux)
extension ChildProcess {
/// A guest keeps its disk image locked for as long as it lives, so the
/// next boot has to wait for this one to be gone rather than merely asked
/// to leave.
func terminateAndWaitForExit() async {
terminate()
let deadline = Date().addingTimeInterval(Self.gracefulExitSeconds)
while isRunning, Date() < deadline {
try? await Task.sleep(for: .milliseconds(50))
}
guard isRunning else { return }
#if !os(Windows)
kill(processIdentifier, SIGKILL)
#endif
while isRunning {
try? await Task.sleep(for: .milliseconds(50))
}
}
private static let gracefulExitSeconds: TimeInterval = 5
}
#endif