在沙盒应用中使用proc_pid_rusage

时间:2017-10-30 16:56:47

标签: macos sandbox appstore-sandbox

我有以下Swift代码来获取硬盘的当前读/写速度:

fileprivate func getIOStatistics() -> (read: UInt64, written: UInt64)
{
    var read: UInt64 = 0
    var written: UInt64 = 0

    for pid in self.getAllRunning()
    {
        var usage = rusage_info_current()

        let result = withUnsafeMutablePointer(to: &usage)
        {
            $0.withMemoryRebound(to: (rusage_info_t?.self), capacity: 1)
            {
                proc_pid_rusage(pid, RUSAGE_INFO_CURRENT, $0)
            }
        }
        if result == 0
        {
            read += usage.ri_diskio_bytesread
            written += usage.ri_diskio_byteswritten
        }
    }

    return (read, written)
}

我只能从正在运行的进程中读取数据。对其他进程的访问受到限制,因为我的应用程序是沙盒。 是否有临时异常密钥,以便我可以访问所有正在运行的进程?

该应用不会直接在Mac App Store中发布。

0 个答案:

没有答案