This preview shows page 1. Sign up to view the full content.
Unformatted text preview: ary function gettimeofday. This function queries the system clock to determine the current date and time.
#include "time.h" struct timeval long tv sec; /* Seconds */ long tv usec; /* Microseconds */ int gettimeofday(struct timeval *tv, NULL);
Returns: 0 for success, -1 for failure The function writes the time into a structure passed by the caller that includes one ﬁeld in units of seconds, and another ﬁeld in units of microseconds. The ﬁrst ﬁeld encodes the total number of seconds that have elapsed since January 1, 1970. (This is the standard reference point for all Unix systems.) Note that the second argument to gettimeofday should simply be NULL on Linux systems, since it refers to an unimplemented feature for performing time zone correction. Practice Problem 9.8:
On what date will the tv sec ﬁeld written by gettimeofday become negative on a 32-bit machine? As shown in Figure 9.20, we can can use gettimeofday to create a pair of timer functions start timer and get timer that are similar to our cycle-timing functions, except that they measur...
View Full Document
- Spring '10
- The American