Time 209
if (clockTicks == 0) { /* Fetch clock ticks on first call */
clockTicks = sysconf(_SC_CLK_TCK);
if (clockTicks == -1)
errExit("sysconf");
}
clockTime = clock();
if (clockTime == -1)
errExit("clock");
printf(" clock() returns: %ld clocks-per-sec (%.2f secs)\n",
(long) clockTime, (double) clockTime / CLOCKS_PER_SEC);
if (times(&t) == -1)
errExit("times");
printf(" times() yields: user CPU=%.2f; system CPU: %.2f\n",
(double) t.tms_utime / clockTicks,
(double) t.tms_stime / clockTicks);
}
int
main(int argc, char *argv[])
{
int numCalls, j;
printf("CLOCKS_PER_SEC=%ld sysconf(_SC_CLK_TCK)=%ld\n\n",
(long) CLOCKS_PER_SEC, sysconf(_SC_CLK_TCK));
displayProcessTimes("At program start:\n");
numCalls = (argc > 1)? getInt(argv[1], GN_GT_0, "num-calls") : 100000000;
for (j = 0; j < numCalls; j++)
(void) getppid();
displayProcessTimes("After getppid() loop:\n");
exit(EXIT_SUCCESS);
}
––––––––––––––––––––––––––––––––––––––––––––––––––––––– time/process_time.c
10.8 Summary..................................................................................................................
Real time corresponds to the everyday definition of time. When real time is mea-
sured from some standard point, we refer to it as calendar time, by contrast with
elapsed time, which is measured from some point (usually the start) in the life of a
process.
Process time is the amount of CPU time used by a process, and is divided into
user and system components.
Various system calls enable us to get and set the system clock value (i.e., calendar
time, as measured in seconds since the Epoch), and a range of library functions allow
conversions between calendar time and other time formats, including broken-down