Skip to content

Commit

Permalink
Update process.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
time-killer-games committed May 15, 2024
1 parent 0ff4750 commit dc39688
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions apiprocess/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,27 @@ namespace ngs::ps {
if (realpath(("/proc/" + std::to_string(proc_id) + "/cwd").c_str(), cwd)) {
path = cwd;
}
#elif defined(__FreeBSD__)
#elif (defined(__FreeBSD__) || defined(__DragonFly__))
int mib[4];
std::size_t len = 0;
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_CWD;
mib[3] = proc_id;
if (!sysctl(mib, 4, nullptr, &len, nullptr, 0)) {
std::vector<char> vecbuff;
vecbuff.resize(len);
char *cwd = &vecbuff[0];
if (!sysctl(mib, 4, cwd, &len, nullptr, 0)) {
char buffer[PATH_MAX];
if (realpath(cwd, buffer)) {
path = buffer;
}
}
}
if (!path.empty())
return path;
#if defined(__FreeBSD__)
int cntp = 0;
kinfo_file *kif = nullptr;
kif = kinfo_file_from_proc_id(proc_id, &cntp);
Expand All @@ -1059,7 +1079,7 @@ namespace ngs::ps {
}
free(kif);
}
#elif defined(__DragonFly__)
#elif defined(__DragonFly__)
FILE *fp = popen(("pos=`ans=\\`/usr/bin/fstat -w -p " + std::to_string(proc_id) + " | /usr/bin/sed -n 1p\\`; " +
"/usr/bin/awk -v ans=\"$ans\" 'BEGIN{print index(ans, \"INUM\")}'`; str=`/usr/bin/fstat -w -p " +
std::to_string(proc_id) + " | /usr/bin/sed -n 3p`; /usr/bin/awk -v str=\"$str\" -v pos=\"$pos\" " +
Expand All @@ -1079,6 +1099,7 @@ namespace ngs::ps {
}
fclose(fp);
}
#endif
#elif defined(__NetBSD__)
int mib[4];
std::size_t len = 0;
Expand Down

0 comments on commit dc39688

Please sign in to comment.