gettimeofday - explanation of the exact struct timeval fields' meaning

3k views Asked by At

I'm trying to write a simple function in C that would calculate the difference between two moments in nanoseconds. To do this, I thought of using the function gettimeofday, which updates the given struct timeval's fields.

As the man page said, the struct timeval's fields are:

time_t      tv_sec;     /* seconds */  
suseconds_t tv_usec;    /* microseconds */  

My question is as follows:

Is the tv_usec field is the WHOLE TIME passed since the EPOCH in microseconds, or is it just the remain of the time in microseconds?

For example, if the time passed is 100 seconds and 25 microseconds, will the tv_usec field have the value '25' or the value '100000025'?

Thanks a lot.

1

There are 1 answers

2
Cat Plus Plus On BEST ANSWER

It's the remainder.

This is the rest of the elapsed time (a fraction of a second), represented as the number of microseconds. It is always less than one million.