I have a simple project with code:
import Foundation
let p1 = UnsafeMutablePointer<rusage_info_t?>.allocate(capacity: 1)
let spid = proc_selfpid()
let s = proc_pid_rusage(579, 0, p1)
if s == KERN_SUCCESS {
// ...
}
print("Status \(status)")
I've added a bridging header:
#ifndef Header_h
#define Header_h
#include <libproc.h>
#include <sys/proc.h>
#endif /* Header_h */
But it strangely cannot find proc_selfpid
saying Cannot find 'proc_selfpid' in scope
while it finds proc_pid_rusage
fine.
I found the definition of proc_pid_rusage
in /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/libproc.h
I can find the definition of proc_selfpid
here /Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/proc.h
I wonder how can I use that SDK implementation in a Swift project?
I have this environment:
uname -mrsv
Darwin 22.4.0 Darwin Kernel Version 22.4.0: Mon Mar 6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000 arm64