简体   繁体   中英

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. 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM