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 
27 namespace core
28 {
29 namespace posix
30 {
31 namespace linux
32 {
33 namespace proc
34 {
35 namespace process
36 {
37 std::istream& operator>>(std::istream& in, State& state)
38 {
39  char c; in >> c; state = static_cast<State>(c);
40  return in;
41 }
42 
43 std::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
53  >> stat.kernel_flags
54  >> stat.minor_faults_count
56  >> stat.major_faults_count
58  >> stat.time.user
59  >> stat.time.system
60  >> stat.time.user_for_children
62  >> stat.priority
63  >> stat.nice
64  >> stat.thread_count
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
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
87  >> stat.guest_time
88  >> stat.guest_time_children;
89 
90  return in;
91 }
92 
93 const posix::Process& operator>>(const posix::Process& process, Stat& stat)
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 }
int session_id
The session ID of the process.
Definition: stat.h:48
pid_t parent
The PID of the parent.
Definition: stat.h:46
std::string executable
The filename of the executable, in parentheses.
Definition: stat.h:44
State state
State of the process.
Definition: stat.h:45
long unsigned int start_code
The address above which program text can run.
Definition: stat.h:89
int exit_signal
Signal to be sent to parent when we die.
Definition: stat.h:105
long unsigned int guest_time
Guest time of the process (time spent running a virtual CPU for a guest operating system)...
Definition: stat.h:110
long unsigned int pending
The bitmap of pending signals, displayed as a decimal number. Obsolete, because it does not provide i...
Definition: stat.h:97
The Process class models a process and possible operations on it.
Definition: process.h:44
unsigned int scheduling_policy
Scheduling policy (see sched_setscheduler(2)). Decode using the SCHED_* constants in linux/sched...
Definition: stat.h:108
long long unsigned int aggregated_block_io_delays
Aggregated block I/O delays, measured in clock ticks (centiseconds).
Definition: stat.h:109
long unsigned int major_faults_count
The number of major faults the process has made which have required loading a memory page from disk...
Definition: stat.h:54
The Stat struct encapsulates status information about a process.
Definition: stat.h:41
struct core::posix::linux::proc::process::Stat::@3 signals
long unsigned int ignored
The bitmap of ignored signals, displayed as a decimal number. Obsolete, because it does not provide i...
Definition: stat.h:99
long unsigned int swap_count_children
Cumulative nswap for child processes (not maintained).
Definition: stat.h:104
long unsigned int swap_count
Number of pages swapped (not maintained).
Definition: stat.h:103
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
long int thread_count
Number of threads in this process (since Linux 2.6).
Definition: stat.h:78
long unsigned int system
Amount of time that this process has been scheduled in kernel mode, [clock ticks].
Definition: stat.h:59
long unsigned int blocked
The bitmap of blocked signals, displayed as a decimal number. Obsolete, because it does not provide i...
Definition: stat.h:98
pid_t process_group
The process group ID of the process.
Definition: stat.h:47
long unsigned int guest_time_children
Guest time of the process&#39;s children, measured in clock ticks.
Definition: stat.h:111
long unsigned int major_faults_count_by_children
The number of major faults that the process&#39;s waited-for children have made.
Definition: stat.h:55
unsigned int kernel_flags
The kernel flags word of the process.
Definition: stat.h:51
long unsigned int user
Amount of time that this process has been scheduled in user mode, [clock ticks].
Definition: stat.h:58
long int nice
The nice value (see setpriority(2)), a value in the range 19 (low priority) to -20 (high priority)...
Definition: stat.h:77
long unsigned int virt
Virtual memory size in bytes.
Definition: stat.h:83
long unsigned int minor_faults_count_by_children
The number of minor faults that the process&#39;s waited-for children have made.
Definition: stat.h:53
virtual pid_t pid() const
Query the pid of the process.
Definition: process.cpp:59
long unsigned int user_for_children
Amount of time that this process&#39;s waited-for children have been scheduled in user mode...
Definition: stat.h:60
struct core::posix::linux::proc::process::Stat::@0 time
long unsigned int instruction_pointer
The current EIP (instruction pointer).
Definition: stat.h:93
long unsigned int system_for_children
Amount of time that this process&#39;s waited-for children have been scheduled in kernel mode...
Definition: stat.h:61
long unsigned int caught
The bitmap of caught signals, displayed as a decimal number. Obsolete, because it does not provide in...
Definition: stat.h:100
int cpu_count
CPU number last executed on.
Definition: stat.h:106
struct core::posix::linux::proc::process::Stat::@2 addresses
pid_t pid
The process ID.
Definition: stat.h:43
long unsigned int start_stack
The address of the start (i.e., bottom) of the stack.
Definition: stat.h:91
long int start_time
The time the process started after system boot. In kernels before Linux 2.6, this value was expressed...
Definition: stat.h:80
int tty_nr
The controlling terminal of the process.
Definition: stat.h:49
long unsigned int end_code
The address below which program text can run.
Definition: stat.h:90
long unsigned int resident_set
Resident Set Size: number of pages the process has in real memory. This is just the pages which count...
Definition: stat.h:84
int controlling_process_group
The ID of the foreground process group of the controlling terminal of the process.
Definition: stat.h:50
unsigned int realtime_priority
Real-time scheduling priority, a number in the range 1 to 99 for processes scheduled under a real-tim...
Definition: stat.h:107
struct core::posix::linux::proc::process::Stat::@1 size
long unsigned int channel
This is the "channel" in which the process is waiting. It is the address of a system call...
Definition: stat.h:102
long unsigned int minor_faults_count
The number of minor faults the process has made which have not required loading a memory page from di...
Definition: stat.h:52
long int time_before_next_sig_alarm
The time in jiffies before the next SIGALRM is sent to the process due to an interval timer...
Definition: stat.h:79
long unsigned int stack_pointer
The current value of ESP (stack pointer), as found in the kernel stack page for the process...
Definition: stat.h:92
long unsigned int resident_set_limit
Current soft limit in bytes on the rss of the process; see the description of RLIMIT_RSS in getrlimit...
Definition: stat.h:85