From 2aa6bdb773d4a6d181cc2ebde8026908c706ac94 Mon Sep 17 00:00:00 2001 From: Kamil Rytarowski Date: Sat, 16 Apr 2016 02:22:23 +0200 Subject: Implement GetProcessIdDisambiguationKey() for NetBSD Make use of the kvm(3) interface to get "struct kinfo_proc2" of the given process. struct kinfo_proc2 { ///.... uint32_t p_ustart_sec; /* STRUCT TIMEVAL: starting time. */ uint32_t p_ustart_usec; /* STRUCT TIMEVAL: starting time. */ ///... }; --- /usr/include/sys/sysctl.h --- src/pal/src/thread/process.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/pal/src/thread/process.cpp b/src/pal/src/thread/process.cpp index 0de235e59c..df9a28b380 100644 --- a/src/pal/src/thread/process.cpp +++ b/src/pal/src/thread/process.cpp @@ -54,6 +54,13 @@ Abstract: #include #endif +#ifdef __NetBSD__ +#include +#include +#include +#include +#endif + using namespace CorUnix; SET_DEFAULT_DEBUG_CHANNEL(PROCESS); @@ -1874,6 +1881,36 @@ GetProcessIdDisambiguationKey(DWORD processId, UINT64 *disambiguationKey) return FALSE; } +#elif defined(__NetBSD__) + + // On NetBSD, we return the process start time expressed in Unix time (the number of seconds + // since the start of the Unix epoch). + kvm_t *kd; + int cnt; + struct kinfo_proc2 *info; + + kd = kvm_open(nullptr, nullptr, nullptr, KVM_NO_FILES, "kvm_open"); + if (kd == nullptr) + { + _ASSERTE(!"Failed to get start time of a process."); + return FALSE; + } + + info = kvm_getproc2(kd, KERN_PROC_PID, processId, sizeof(struct kinfo_proc2), &cnt); + if (info == nullptr || cnt < 1) + { + kvm_close(kd); + _ASSERTE(!"Failed to get start time of a process."); + return FALSE; + } + + kvm_close(kd); + + long secondsSinceEpoch = info->p_ustart_sec; + *disambiguationKey = secondsSinceEpoch; + + return TRUE; + #elif defined(HAVE_PROCFS_CTL) // Here we read /proc//stat file to get the start time for the process. -- cgit v1.2.3