[Previous]
[Contents]
[Next]

times()

get time-accounting information

Synopsis:

#include <sys/times.h>
clock_t times( struct tms *buffer );

Description:

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 member tms_utime is the CPU time charged for the execution of user instruction.
clock_t tms_stime
The member tms_stime is the CPU time charged for execution by the system on behalf of the process.
clock_t tms_cutime
The member tms_cutime is the sum of the tms_utime for this process, and the tms_cutime values of the child processes.
clock_t tms_cstime
The value tms_cstime is the sum of the tms_stime and the 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. 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 parent process hasn't waited for its terminated children, their times aren't included in its times.

Returns:

The elapsed real time, in CLK_TCK'ths of a second, since the process was started. The value returned may overflow the possible range of type clock_t.


Note: The data returned by times() is valid only if time accounting is enabled. This is the default, but it may be disabled to save time and memory when an operating system image is built using the buildqnx utility. When disabled, the struct tms members will always be zero.

Examples:

/*
 * 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>

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

    system( argv[1] );
    times( &childtim );
    printf( "system time = %ld\n", childtim.tms_cstime );
    printf( "user time   = %ld\n", childtim.tms_cutime );
    exit( 0 );
  }

Classification:

POSIX 1003.1

Safety:
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

clock_gettime()


[Previous]
[Contents]
[Next]