stat.cpp
Go to the documentation of this file.
/*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Thomas Voß <thomas.voss@canonical.com>
*/
#include <core/posix/linux/proc/process/stat.h>
#include <core/posix/process.h>
#include <fstream>
#include <istream>
#include <sstream>
namespace core
{
namespace posix
{
namespace linux
{
namespace proc
{
namespace process
{
std::istream& operator>>(std::istream& in, State& state)
{
char c; in >> c; state = static_cast<State>(c);
return in;
}
std::istream& operator>>(std::istream& in, Stat& stat)
{
in >> stat.pid
>> stat.executable
>> stat.state
>> stat.parent
>> stat.process_group
>> stat.session_id
>> stat.tty_nr
>> stat.controlling_process_group
>> stat.kernel_flags
>> stat.minor_faults_count
>> stat.minor_faults_count_by_children
>> stat.major_faults_count
>> stat.major_faults_count_by_children
>> stat.time.user
>> stat.time.system
>> stat.time.user_for_children
>> stat.time.system_for_children
>> stat.priority
>> stat.nice
>> stat.thread_count
>> stat.time_before_next_sig_alarm
>> stat.start_time
>> stat.size.virt
>> stat.size.resident_set
>> stat.size.resident_set_limit
>> stat.addresses.start_code
>> stat.addresses.end_code
>> stat.addresses.start_stack
>> stat.addresses.stack_pointer
>> stat.addresses.instruction_pointer
>> stat.signals.pending
>> stat.signals.blocked
>> stat.signals.ignored
>> stat.signals.caught
>> stat.channel
>> stat.swap_count
>> stat.swap_count_children
>> stat.exit_signal
>> stat.cpu_count
>> stat.realtime_priority
>> stat.scheduling_policy
>> stat.aggregated_block_io_delays
>> stat.guest_time
>> stat.guest_time_children;
return in;
}
const posix::Process& operator>>(const posix::Process& process, Stat& stat)
{
std::stringstream ss; ss << "/proc/" << process.pid() << "/stat";
std::ifstream in(ss.str());
in >> stat;
return process;
}
}
}
}
}
}
core::posix::Process
The Process class models a process and possible operations on it.
Definition process.h:45
core::posix::linux::proc::process
Definition stat.h:37
core::posix::linux::proc::process::State
State
Definition state.h:36
core::posix::linux::proc::process::operator>>
CORE_POSIX_DLL_PUBLIC const posix::Process & operator>>(const posix::Process &process, Stat &stat)
Definition stat.cpp:93
core::posix::linux::proc
Definition stat.h:35
core::posix::linux
Definition stat.h:33
core::posix
Definition child_process.h:34
core
Definition child_process.h:32
process.h
stat.h
core::posix::linux::proc::process::Stat
The Stat struct encapsulates status information about a process.
Definition stat.h:42
core::posix::linux::proc::process::Stat::state
State state
State of the process.
Definition stat.h:45
core::posix::linux::proc::process::Stat::exit_signal
int exit_signal
Signal to be sent to parent when we die.
Definition stat.h:105
core::posix::linux::proc::process::Stat::addresses
struct core::posix::linux::proc::process::Stat::@200204336001247264303015252361163213015040130153 addresses
core::posix::linux::proc::process::Stat::guest_time_children
long unsigned int guest_time_children
Guest time of the process's children, measured in clock ticks.
Definition stat.h:111
core::posix::linux::proc::process::Stat::time
struct core::posix::linux::proc::process::Stat::@236056257116110366303351341037310122171006241355 time
core::posix::linux::proc::process::Stat::thread_count
long int thread_count
Number of threads in this process (since Linux 2.6).
Definition stat.h:78
core::posix::linux::proc::process::Stat::size
struct core::posix::linux::proc::process::Stat::@054051211025331130372072205012220066153242204202 size
core::posix::linux::proc::process::Stat::major_faults_count_by_children
long unsigned int major_faults_count_by_children
The number of major faults that the process's waited-for children have made.
Definition stat.h:55
core::posix::linux::proc::process::Stat::channel
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
core::posix::linux::proc::process::Stat::parent
pid_t parent
The PID of the parent.
Definition stat.h:46
core::posix::linux::proc::process::Stat::major_faults_count
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
core::posix::linux::proc::process::Stat::session_id
int session_id
The session ID of the process.
Definition stat.h:48
core::posix::linux::proc::process::Stat::nice
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
core::posix::linux::proc::process::Stat::resident_set
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
core::posix::linux::proc::process::Stat::aggregated_block_io_delays
long long unsigned int aggregated_block_io_delays
Aggregated block I/O delays, measured in clock ticks (centiseconds).
Definition stat.h:109
core::posix::linux::proc::process::Stat::minor_faults_count_by_children
long unsigned int minor_faults_count_by_children
The number of minor faults that the process's waited-for children have made.
Definition stat.h:53
core::posix::linux::proc::process::Stat::executable
std::string executable
The filename of the executable, in parentheses.
Definition stat.h:44
core::posix::linux::proc::process::Stat::process_group
pid_t process_group
The process group ID of the process.
Definition stat.h:47
core::posix::linux::proc::process::Stat::system_for_children
long unsigned int system_for_children
Amount of time that this process's waited-for children have been scheduled in kernel mode,...
Definition stat.h:61
core::posix::linux::proc::process::Stat::swap_count
long unsigned int swap_count
Number of pages swapped (not maintained).
Definition stat.h:103
core::posix::linux::proc::process::Stat::swap_count_children
long unsigned int swap_count_children
Cumulative nswap for child processes (not maintained).
Definition stat.h:104
core::posix::linux::proc::process::Stat::blocked
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
core::posix::linux::proc::process::Stat::minor_faults_count
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
core::posix::linux::proc::process::Stat::start_stack
long unsigned int start_stack
The address of the start (i.e., bottom) of the stack.
Definition stat.h:91
core::posix::linux::proc::process::Stat::instruction_pointer
long unsigned int instruction_pointer
The current EIP (instruction pointer).
Definition stat.h:93
core::posix::linux::proc::process::Stat::kernel_flags
unsigned int kernel_flags
The kernel flags word of the process.
Definition stat.h:51
core::posix::linux::proc::process::Stat::caught
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
core::posix::linux::proc::process::Stat::end_code
long unsigned int end_code
The address below which program text can run.
Definition stat.h:90
core::posix::linux::proc::process::Stat::system
long unsigned int system
Amount of time that this process has been scheduled in kernel mode, [clock ticks].
Definition stat.h:59
core::posix::linux::proc::process::Stat::stack_pointer
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
core::posix::linux::proc::process::Stat::pending
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
core::posix::linux::proc::process::Stat::virt
long unsigned int virt
Virtual memory size in bytes.
Definition stat.h:83
core::posix::linux::proc::process::Stat::guest_time
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
core::posix::linux::proc::process::Stat::cpu_count
int cpu_count
CPU number last executed on.
Definition stat.h:106
core::posix::linux::proc::process::Stat::tty_nr
int tty_nr
The controlling terminal of the process.
Definition stat.h:49
core::posix::linux::proc::process::Stat::controlling_process_group
int controlling_process_group
The ID of the foreground process group of the controlling terminal of the process.
Definition stat.h:50
core::posix::linux::proc::process::Stat::priority
long int priority
Definition stat.h:76
core::posix::linux::proc::process::Stat::start_time
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
core::posix::linux::proc::process::Stat::start_code
long unsigned int start_code
The address above which program text can run.
Definition stat.h:89
core::posix::linux::proc::process::Stat::resident_set_limit
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
core::posix::linux::proc::process::Stat::signals
struct core::posix::linux::proc::process::Stat::@305060023120377052144333107233322370275131157054 signals
core::posix::linux::proc::process::Stat::pid
pid_t pid
The process ID.
Definition stat.h:43
core::posix::linux::proc::process::Stat::realtime_priority
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
core::posix::linux::proc::process::Stat::user_for_children
long unsigned int user_for_children
Amount of time that this process's waited-for children have been scheduled in user mode,...
Definition stat.h:60
core::posix::linux::proc::process::Stat::user
long unsigned int user
Amount of time that this process has been scheduled in user mode, [clock ticks].
Definition stat.h:58
core::posix::linux::proc::process::Stat::scheduling_policy
unsigned int scheduling_policy
Scheduling policy (see sched_setscheduler(2)). Decode using the SCHED_* constants in linux/sched....
Definition stat.h:108
core::posix::linux::proc::process::Stat::ignored
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
core::posix::linux::proc::process::Stat::time_before_next_sig_alarm
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