/* * Sample program for times system call - No.43 * * times(2) - get process times * * Synopsis * #include * * clock_t times(struct tms *buf); * * Description * The times() function stores the current process times in * the struct tms that buf points to. The struct tms is as * defined in * * typedef long int clock_t; * * struct tms { * clock_t tms_utime; * user time * * clock_t tms_stime; * system time * * clock_t tms_cutime; * user time of children * * clock_t tms_cstime; * system time of children * * }; * * The tms_utime field contains the CPU time spent executing * instructions of the calling process. The tms_stime field * contains the CPU time spent in the system while executing * field contains the sum of the tms_time and tms_cutime values * vor all waited-for terminated children. The tms_cstime field * contains the sum of the tms_stime and tms_cstime values for * all waited-for terminated children. * * Times for terminated children (and their descendants) is * added in at the moment wait(2) or waitpid(2) returns their * process ID. In particular, times of grandchildren that the * children did not wait fro are never seen. * * All times reported are in clock ticks. */ #include #include main() { struct tms tm_start, tm_end; int i; times(&tm_start); for (i = 0; i < 10000000; i++); times(&tm_end); printf("%ld ticks.\n", tm_end.tms_utime - tm_start.tms_utime); exit(0); }