本文介绍了Swift macOS Process.run()端口泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当前代码:
#!/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()
}
在活动监视器中,似乎马赫端口的使用在每个循环中增加了1.运行外部进程时,这是预期的行为吗?如果没有,如何解决泄漏?谢谢.
Looking in activity monitor, it seems that the mach port usage increases by 1 each loop. Is this expected behavior when running an external process? If not, how do I fix the leak? Thanks.
推荐答案
这不是预期的行为,并且已经报告了此问题.解决方法是使用posix_spawn
代替Process
.
It's not expected behaviour and this problem is already reported. The workaround for this is using posix_spawn
instead of Process
.
这篇关于Swift macOS Process.run()端口泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!