1

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
egor10_4
  • 331
  • 2
  • 9
  • Any reason you can't use `ProcessInfo.processInfo.processIdentifier`? – Sweeper Apr 16 '23 at 14:17
  • 1
    I need other functions too, ie `proc_selfppid`, `proc_find`. – egor10_4 Apr 16 '23 at 19:01
  • Your newer question is basically a duplicate of this one, should I close this one? https://stackoverflow.com/q/76034307/3141234 – Alexander Apr 18 '23 at 13:13
  • It's completely different, I see 2 different header files locations and there's no information how it's used by Swift environment? Why one header can be included by bridging and the other won't? It's still a puzzle to me. – egor10_4 Apr 18 '23 at 14:41

0 Answers0