diff options
Diffstat (limited to 'src/helpers/MiscFunctions.cpp')
| -rw-r--r-- | src/helpers/MiscFunctions.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index 22afd4a0..e933d496 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -354,3 +354,38 @@ void matrixProjection(float mat[9], int w, int h, wl_output_transform tr) { // Identity mat[8] = 1.0f; } + +int64_t getPPIDof(int64_t pid) { + std::string dir = "/proc/" + std::to_string(pid) + "/status"; + FILE* infile; + + infile = fopen(dir.c_str(), "r"); + if (!infile) + return 0; + + char* line = nullptr; + size_t len = 0; + ssize_t len2 = 0; + + std::string pidstr; + + while ((len2 = getline(&line, &len, infile)) != -1) { + if (strstr(line, "PPid:")) { + pidstr = std::string(line, len2); + const auto tabpos = pidstr.find_last_of('\t'); + if (tabpos != std::string::npos) + pidstr = pidstr.substr(tabpos); + break; + } + } + + fclose(infile); + if (line) + free(line); + + try { + return std::stoll(pidstr); + } catch (std::exception& e) { + return 0; + } +}
\ No newline at end of file |
