File indexing completed on 2024-05-12 05:32:15

0001 /*
0002    SPDX-FileCopyrightText: 2021 Tobias C. Berner <tcberner@FreeBSD.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include <sys/param.h>
0008 #include <sys/sysctl.h>
0009 #include <sys/types.h>
0010 
0011 #include "executable_path.h"
0012 
0013 QString executablePathFromPid(pid_t pid)
0014 {
0015     const int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, static_cast<int>(pid)};
0016     char buf[MAXPATHLEN];
0017     size_t cb = sizeof(buf);
0018     if (sysctl(mib, 4, buf, &cb, nullptr, 0) == 0) {
0019         return QString::fromLocal8Bit(realpath(buf, nullptr));
0020     }
0021     return QString();
0022 }