Swift macOS Process.run() port leak

谁都会走 提交于 2019-12-06 06:24:47

问题


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. Is this expected behavior when running an external process? If not, how do I fix the leak? Thanks.


回答1:


It's not expected behaviour and this problem is already reported. The workaround for this is using posix_spawn instead of Process.



来源:https://stackoverflow.com/questions/55288194/swift-macos-process-run-port-leak

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!