KWin
Loading...
Searching...
No Matches
executable_path_sysctl.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2021 Tobias C. Berner <tcberner@FreeBSD.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include <sys/param.h>
8#include <sys/sysctl.h>
9#include <sys/types.h>
10
11#include "executable_path.h"
12
13QString executablePathFromPid(pid_t pid)
14{
15 const int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, static_cast<int>(pid)};
16 char buf[MAXPATHLEN];
17 size_t cb = sizeof(buf);
18 if (sysctl(mib, 4, buf, &cb, nullptr, 0) == 0) {
19 return QString::fromLocal8Bit(realpath(buf, nullptr));
20 }
21 return QString();
22}
QString executablePathFromPid(pid_t pid)