title: What is the proper way to use clock_gettime()?
body: <p>I was trying out this function in a C program, and it keeps printing the wrong time.  This is my code at the moment:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;time.h&gt;
  #include &lt;sys/resource.h&gt;
  
  int main( int argc, char **argv ){
      struct timespec start, finish;
      clock_gettime( CLOCK_REALTIME, &amp;start );
      sleep( 1 );
      clock_gettime( CLOCK_REALTIME, &amp;finish );
      printf( "%f\n", ((double) (finish.tv_nsec - start.tv_nsec))/((double) 100000) );
      return 0;
  }
  </code></pre>
  
  <p>I'm not sure if this is an anomaly caused by rounding errors when converting to a <code>double</code> or if I'm using the <code>clock_gettime()</code> function incorrectly, but I expected it to output 1 second and instead it outputs 1.27 seconds.</p>