Adam S
02/14/2025, 10:03 AM/proc
and `platform.posix.realpath`:
import kotlinx.cinterop.refTo
import kotlinx.cinterop.toKString
import platform.posix.PATH_MAX
import platform.posix.realpath
actual fun processPath(pid: UInt): String? {
val buffer = ByteArray(PATH_MAX)
val procPath = "/proc/$pid/exe"
if (realpath(procPath, buffer.refTo(0)) == null) {
return null
}
return buffer.toKString()
}
But iiuc /proc
doesn't exist on macOS. Instead there's proc_pidpath()
example, but K/N doesn't have a generated function for that. Is there another way?Adam S
02/14/2025, 11:09 AMproc_pidpath()
. IntelliJ sync wasn't working properly, so autocomplete wasn't working. I cleaned out all of the build/
, .kotlin/
and .gradle/
dirs and resynced, and it works now:
import kotlinx.cinterop.refTo
import kotlinx.cinterop.toKString
import platform.osx.proc_pidpath
import platform.posix.PATH_MAX
actual fun processPath(pid: UInt): String? {
val buffer = ByteArray(PATH_MAX)
val ret = proc_pidpath(pid = pid.toInt(), buffer.refTo(0), PATH_MAX.toUInt())
return if (ret <= 0) {
null
} else {
buffer.toKString()
}
}