Get time-accounting information


#include <sys/times.h>

clock_t times( struct tms* buffer );


BlackBerry 10.0.0


A pointer to a tms structure where the function can store the time-accounting information. For information about the tms structure, see below.



Use the -l c option to qcc to link against this library. This library is usually included automatically.


The times() function stores time-accounting information in the structure pointed to by buffer. The type clock_t and the tms structure are defined in the <sys/times.h> header file.

The tms structure contains at least the following members:

clock_t tms_utime
The CPU time charged for the execution of user instructions of the calling process.
clock_t tms_stime
The CPU time charged for execution by the system on behalf of the calling process.
clock_t tms_cutime
The sum of the tms_utime and tms_cutime values of the child processes.
clock_t tms_cstime
The sum of the tms_stime and tms_cstime values of the child processes.

All times are in CLK_TCK'ths of a second. CLK_TCK is defined in the <time.h> header file. A CLK_TCK is the equivalent of:

#define sysconf( _SC_CLK_TCK )

The times of a terminated child process are included in the tms_cutime and tms_cstime elements of the parent when a wait() or waitpid() function returns the process ID of this terminated child. If a child process hasn't waited for its terminated children, their times aren't included in its times.


The elapsed real time, in clock ticks, of kernel uptime.

The value returned may overflow the possible range of type clock_t.


 * The following program executes the program
 * specified by argv[1].  After the child program
 * is finished, the cpu statistics of the child are
 * printed.
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/times.h>

int main( int argc, char **argv )
    struct tms childtim;

    system( argv[1] );
    times( &childtim );
    printf( "system time = %d\n", childtim.tms_cstime );
    printf( "user time   = %d\n", childtim.tms_cutime );
    return EXIT_SUCCESS;


POSIX 1003.1

Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes

Last modified: 2014-06-24

Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus