process-cpp 3.0.0
A simple convenience library for handling processes in C++11.
stat.cpp
Go to the documentation of this file.
1/*
2 * Copyright © 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Thomas Voß <thomas.voss@canonical.com>
17 */
18
20
21#include <core/posix/process.h>
22
23#include <fstream>
24#include <istream>
25#include <sstream>
26
27namespace core
28{
29namespace posix
30{
31namespace linux
32{
33namespace proc
34{
35namespace process
36{
37std::istream& operator>>(std::istream& in, State& state)
38{
39 char c; in >> c; state = static_cast<State>(c);
40 return in;
41}
42
43std::istream& operator>>(std::istream& in, Stat& stat)
44{
45 in >> stat.pid
46 >> stat.executable
47 >> stat.state
48 >> stat.parent
49 >> stat.process_group
50 >> stat.session_id
51 >> stat.tty_nr
52 >> stat.controlling_process_group
53 >> stat.kernel_flags
54 >> stat.minor_faults_count
55 >> stat.minor_faults_count_by_children
56 >> stat.major_faults_count
57 >> stat.major_faults_count_by_children
58 >> stat.time.user
59 >> stat.time.system
60 >> stat.time.user_for_children
61 >> stat.time.system_for_children
62 >> stat.priority
63 >> stat.nice
64 >> stat.thread_count
65 >> stat.time_before_next_sig_alarm
66 >> stat.start_time
67 >> stat.size.virt
68 >> stat.size.resident_set
69 >> stat.size.resident_set_limit
70 >> stat.addresses.start_code
71 >> stat.addresses.end_code
72 >> stat.addresses.start_stack
73 >> stat.addresses.stack_pointer
74 >> stat.addresses.instruction_pointer
75 >> stat.signals.pending
76 >> stat.signals.blocked
77 >> stat.signals.ignored
78 >> stat.signals.caught
79 >> stat.channel
80 >> stat.swap_count
81 >> stat.swap_count_children
82 >> stat.exit_signal
83 >> stat.cpu_count
84 >> stat.realtime_priority
85 >> stat.scheduling_policy
86 >> stat.aggregated_block_io_delays
87 >> stat.guest_time
88 >> stat.guest_time_children;
89
90 return in;
91}
92
94{
95 std::stringstream ss; ss << "/proc/" << process.pid() << "/stat";
96 std::ifstream in(ss.str());
97
98 in >> stat;
99
100 return process;
101}
102}
103}
104}
105}
106}
The Process class models a process and possible operations on it.
Definition process.h:45
virtual pid_t pid() const
Query the pid of the process.
Definition process.cpp:59
CORE_POSIX_DLL_PUBLIC const posix::Process & operator>>(const posix::Process &process, OomAdj &adj)
Read the OomAdj value for a process instance.
Definition oom_adj.cpp:55
Signal
The Signal enum collects the most common POSIX signals.
Definition signal.h:39
The Stat struct encapsulates status information about a process.
Definition stat.h:42