get time-accounting information
#include <sys/times.h> clock_t times( struct tms *buffer );
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:
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.
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.
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. |
/* * 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 ); }
POSIX 1003.1
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |