Results 1 to 3 of 3
Hi there,
I am having problem understanding the result of gettimeofday() call. In my understanding, it returns a struct of timeval, which has the definition
Code:
struct timeval {
time_t ...
- 11-08-2010 #1Just Joined!
- Join Date
- Oct 2010
- Posts
- 7
gettimeofday() format
Hi there,
I am having problem understanding the result of gettimeofday() call. In my understanding, it returns a struct of timeval, which has the definitionThe tv_sec part of the return value represents the seconds part since the Epoch, and tv_usec represents the microsecond part, meaning that these two parts are sort of irrelevant, right? However, if I do a call like this:Code:struct timeval { time_t tv_sec; /* seconds */ suseconds_t tv_usec; /* microseconds */ };which, by the way, is from one example from online. The result is beyond my understanding that the tv_usec part is always larger than the tv_sec part by 4. For example, one output would be: 3216945432.3216945436 But like I said, should these two parts be irrelevant? Or is there any misunderstanding? Thanks for any help!Code:struct timeval tv; gettimeofday(&tv); printf("%u.%u \n",&tv.tv_sec,&tv.tv_usec);
- 11-08-2010 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Remove the & from &tv.tv_sec and &tv.tv_usec in the printf() call. In order to convert the tv.tv_sec to a sensible date+time value you would use one of the related functions, such as ctime(). See you system man pages for more details.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 11-09-2010 #3Just Joined!
- Join Date
- Oct 2010
- Posts
- 7


Reply With Quote
