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