resource_usage |
The kernel tracks the resource usage of every process, including the amount of CPU time used and the number of signals received. A resource usage object is read-only and can be queried for its individual resource values, if required.
To receive a resource object
containing its resource statistics, use the method os_this_process::usage()
. To obtain resource statistics for the terminated child processes of the
current process, use os_this_process::usage_for_terminated_children()
.
The following example requests the resource usage of the resource object.
#include <iostream>
#include <ospace/unix.h>
int
main()
{
os_unix_toolkit initialize;
os_process child( "/bin/sh", "date" );
// Usage becomes available when child terminates.
os_this_process::wait_for_child( child );
os_resource_usage usage = os_this_process::usage();
cout << "os_resource_usage" << endl;
cout
<< " user time: " << usage.user_time() << endl
<< " system time: " << usage.system_time() << endl
<< " max resident set (bytes): " << usage.max_resident_set_bytes()
<< endl
<< " average resident set (pages): "
<< usage.average_resident_set_pages() << endl
<< " average resident set (bytes): "
<< usage.average_resident_set_bytes() << endl
<< " page faults without I/O: " << usage.non_io_page_faults()
<< endl
<< " page faults with I/O: " << usage.io_page_faults() << endl
<< " number of swaps: " << usage.swaps() << endl
<< " blocks on input: " << usage.input_blocks() << endl
<< " blocks on output: " << usage.output_blocks() << endl
<< " messages sent: " << usage.sent_messages() << endl
<< " messages received: " << usage.received_messages() << endl
<< " signals received: " << usage.received_signals() << endl
<< " voluntary context switches: "
<< usage.voluntary_context_switches() << endl
<< " forced context switches: " << usage.forced_context_switches()
<< endl;
return 0;
}
Sat Jul 8 21:01:20 CDT 1995
user time: 0.090000 seconds
system time: 0.110000 seconds
max resident set (bytes): 946176
average resident set (pages): 41
average resident set (bytes): 167936
page faults without I/O: 283
page faults with I/O: 0
number of swaps: 0
blocks on input: 2
blocks on output: 0
messages sent: 0
messages received: 0
signals received: 0
voluntary context switches: 2
forced context switches: 7
Copyright©1994-2026 Recursion
Software LLC
All Rights Reserved - For use by licensed users only.