[英]Swift macOS Process.run() port leak
Current code:当前代码:
#!/usr/bin/swift
import Foundation
func runSleepProcess() {
let sleepProcess = Process()
sleepProcess.executableURL = URL(fileURLWithPath: "/bin/sleep")
sleepProcess.arguments = ["0"]
try? sleepProcess.run()
sleepProcess.waitUntilExit()
}
while true {
runSleepProcess()
}
Looking in activity monitor, it seems that the mach port usage increases by 1 each loop.查看活动监视器,似乎每个循环的 mach 端口使用量增加 1。 Is this expected behavior when running an external process?这是运行外部进程时的预期行为吗? If not, how do I fix the leak?如果没有,我该如何解决泄漏问题? Thanks.谢谢。
It's not expected behaviour and this problem is already reported.这不是预期的行为,并且已经报告了此问题。 The workaround for this is using posix_spawn
instead of Process
.解决方法是使用posix_spawn
而不是Process
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.