Something went wrong. Try again.
The agentic engineering control plane for the posthuman future
Something went wrong. Try again.
1.1 kB · 57 lines
C++
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758#include "ProcessCwd.h"
#ifdef __APPLE__#include <libproc.h>#elifdef __linux__#include <unistd.h>#include <cerrno>#include <filesystem>#endif
#ifdef __APPLE__
QString processCwd(qint64 pid) { if (pid <= 0) { return {}; } struct proc_vnodepathinfo info{}; const int ret = proc_pidinfo(static_cast<int>(pid), PROC_PIDVNODEPATHINFO, 0, &info, sizeof(info)); if (ret != sizeof(info)) { return {}; } const char* path = info.pvi_cdir.vip_path; if (path[0] == '\0') { return {}; } return QString::fromLocal8Bit(path);}
#elifdef __linux__
QString processCwd(qint64 pid) { if (pid <= 0) { return {}; } std::error_code ec; const std::filesystem::path link = std::filesystem::read_symlink( "/proc/" + std::to_string(pid) + "/cwd", ec); if (ec) { return {}; } const std::string path = link.string(); if (path.empty()) { return {}; } return QString::fromLocal8Bit(path.data(), static_cast<qsizetype>(path.size()));}
#else
QString processCwd(qint64 pid) { Q_UNUSED(pid); return {};}
#endif