getrusage

Gets the current resource usages

Syntax

getrusage(int $mode = 0): array|false

Parameters

mode

If mode is 1, getrusage will be called with RUSAGE_CHILDREN.

Return

Returns an associative array containing the data returned from the system call. All entries are accessible by using their documented field names. Returns false on failure.

Examples

1 · void

<?

$return = getrusage();

print_r($return);

?>
Array
(
    [ru_oublock] => 0
    [ru_inblock] => 0
    [ru_msgsnd] => 0
    [ru_msgrcv] => 0
    [ru_maxrss] => 14104
    [ru_ixrss] => 0
    [ru_idrss] => 0
    [ru_minflt] => 429
    [ru_majflt] => 0
    [ru_nsignals] => 0
    [ru_nvcsw] => 0
    [ru_nivcsw] => 0
    [ru_nswap] => 0
    [ru_utime.tv_usec] => 883
    [ru_utime.tv_sec] => 0
    [ru_stime.tv_usec] => 1740
    [ru_stime.tv_sec] => 0
)

2 · mode

<?

$mode = 2;

$return = getrusage($mode);

print_r($return);

?>
Array
(
    [ru_oublock] => 0
    [ru_inblock] => 0
    [ru_msgsnd] => 0
    [ru_msgrcv] => 0
    [ru_maxrss] => 14104
    [ru_ixrss] => 0
    [ru_idrss] => 0
    [ru_minflt] => 432
    [ru_majflt] => 0
    [ru_nsignals] => 0
    [ru_nvcsw] => 0
    [ru_nivcsw] => 0
    [ru_nswap] => 0
    [ru_utime.tv_usec] => 0
    [ru_utime.tv_sec] => 0
    [ru_stime.tv_usec] => 3022
    [ru_stime.tv_sec] => 0
)

3 · field names

<?

$return = getrusage();

echo $return["ru_oublock"] . ": ru_oublock: number of block output operations\n";
echo $return["ru_inblock"] . ": ru_inblock: number of block input operations\n";
echo $return["ru_msgsnd"] . ": ru_msgsnd: number of IPC messages sent\n";
echo $return["ru_msgrcv"] . ": ru_msgrcv: number of IPC messages received\n";
echo $return["ru_maxrss"] . ": ru_maxrss: maximum resident set size\n";
echo $return["ru_ixrss"] . ": ru_ixrss: integral shared memory size\n";
echo $return["ru_idrss"] . ": ru_idrss: integral unshared data size\n";
echo $return["ru_minflt"] . ": ru_minflt: number of page reclaims (soft page faults)\n";
echo $return["ru_majflt"] . ": ru_majflt: number of page faults (hard page faults)\n";
echo $return["ru_nsignals"] . ": ru_nsignals: number of signals received\n";
echo $return["ru_nvcsw"] . ": ru_nvcsw: number of voluntary context switches\n";
echo $return["ru_nivcsw"] . ": ru_nivcsw: number of involuntary context switches\n";
echo $return["ru_nswap"] . ": ru_nswap: number of swaps\n";
echo $return["ru_utime.tv_usec"] . ": ru_utime.tv_usec: user time used (microseconds)\n";
echo $return["ru_utime.tv_sec"] . ": ru_utime.tv_sec: user time used (seconds)\n";
echo $return["ru_stime.tv_usec"] . ": ru_stime.tv_usec: system time used (microseconds)\n";

?>
0: ru_oublock: number of block output operations
0: ru_inblock: number of block input operations
0: ru_msgsnd: number of IPC messages sent
0: ru_msgrcv: number of IPC messages received
15736: ru_maxrss: maximum resident set size
0: ru_ixrss: integral shared memory size
0: ru_idrss: integral unshared data size
496: ru_minflt: number of page reclaims (soft page faults)
0: ru_majflt: number of page faults (hard page faults)
0: ru_nsignals: number of signals received
1: ru_nvcsw: number of voluntary context switches
0: ru_nivcsw: number of involuntary context switches
0: ru_nswap: number of swaps
971: ru_utime.tv_usec: user time used (microseconds)
0: ru_utime.tv_sec: user time used (seconds)
3022: ru_stime.tv_usec: system time used (microseconds)
HomeMenu