forked from qt-creator/qt-creator
Utils: Use "exe" column from ps
On Linux we can get the executable name directly via the "exe"
column. On macOS we can continue to use "comm" which
gives us the same information there.
"comm" on Linux though is the current value of the processes
"argv[0]".
Amends 2d0fc6a3ba
Change-Id: I6405f08e815806bb7edd9654f2891701320f5e3d
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -148,11 +148,13 @@ static Result<QList<ProcessInfo>> getLocalProcessesUsingPs(const FilePath &devic
|
|||||||
|
|
||||||
// cmdLines are full command lines, usually with absolute path,
|
// cmdLines are full command lines, usually with absolute path,
|
||||||
// exeNames only the file part of the executable's path.
|
// exeNames only the file part of the executable's path.
|
||||||
const auto exeNames = getLocalProcessDataUsingPs(ps, "comm");
|
using namespace Qt::Literals;
|
||||||
|
const QString exeNameColumn = deviceRoot.osType() == OsTypeMac ? "comm"_L1 : "exe"_L1;
|
||||||
|
const Result<QMap<qint64, QString>> exeNames = getLocalProcessDataUsingPs(ps, exeNameColumn);
|
||||||
if (!exeNames)
|
if (!exeNames)
|
||||||
return ResultError(exeNames.error());
|
return ResultError(exeNames.error());
|
||||||
|
|
||||||
const auto cmdLines = getLocalProcessDataUsingPs(ps, "args");
|
const Result<QMap<qint64, QString>> cmdLines = getLocalProcessDataUsingPs(ps, "args");
|
||||||
if (!cmdLines)
|
if (!cmdLines)
|
||||||
return ResultError(cmdLines.error());
|
return ResultError(cmdLines.error());
|
||||||
|
|
||||||
@@ -166,10 +168,7 @@ static Result<QList<ProcessInfo>> getLocalProcessesUsingPs(const FilePath &devic
|
|||||||
const QString exeName = it.value();
|
const QString exeName = it.value();
|
||||||
if (exeName.isEmpty())
|
if (exeName.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
const int pos = cmdLine.indexOf(exeName);
|
processes.append({pid, exeName, cmdLine});
|
||||||
if (pos == -1)
|
|
||||||
continue;
|
|
||||||
processes.append({pid, cmdLine.left(pos + exeName.size()), cmdLine});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return processes;
|
return processes;
|
||||||
|
Reference in New Issue
Block a user