KCoreAddons

kprocesslist_unix_procstat.cpp
1 /*
2 
3  This file is part of the KDE Frameworks
4 
5  SPDX-FileCopyrightText: 2019 Tobias C. Berner <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.1-only
8 */
9 
10 #include "kprocesslist.h"
11 #include "kprocesslist_unix_procstat_p.h"
12 
13 #include <QDir>
14 #include <QProcess>
15 
16 using namespace KProcessList;
17 
18 // Determine UNIX processes by using the procstat library
19 KProcessInfoList KProcessList::processInfoList()
20 {
22 
23  ProcStat pstat;
24  if (!pstat) {
25  return rc;
26  }
27 
28  ProcStatProcesses procs(pstat);
29  for (const auto &process_info : procs) {
30  rc.push_back(process_info);
31  }
32 
33  return rc;
34 }
35 
36 KProcessInfo KProcessList::processInfo(qint64 pid)
37 {
38  KProcessInfoList processInfoList = KProcessList::processInfoList();
39  auto testProcessIterator = std::find_if(processInfoList.begin(), processInfoList.end(), [pid](const KProcessList::KProcessInfo &info) {
40  return info.pid() == pid;
41  });
42  if (testProcessIterator != processInfoList.end()) {
43  return *testProcessIterator;
44  }
45  return KProcessInfo();
46 }
Contains information about a process.
Definition: kprocesslist.h:27
void push_back(const T &value)
QList::iterator end()
QList::iterator begin()
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Apr 22 2021 23:02:15 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.