Created
December 4, 2014 02:01
-
-
Save scari/7c49683bcb4d08e65156 to your computer and use it in GitHub Desktop.
using posix clock example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <time.h> | |
#include <stdio.h> | |
int | |
main(int argc, char* argv[]) { | |
struct timespec ts; | |
struct timespec delay = { .tv_sec = 0, .tv_nsec = 1000 }; | |
int res = -1; | |
clockid_t clk = CLOCK_REALTIME; | |
res = clock_getres(clk, &ts); | |
if (0 == res) printf("%ld %ld\n", ts.tv_sec, ts.tv_nsec); | |
res = clock_gettime(clk, &ts); | |
if (0 == res) printf("%ld %ld\n", ts.tv_sec, ts.tv_nsec); | |
clock_nanosleep(clk, 0, &delay, NULL); | |
res = clock_gettime(clk, &ts); | |
if (0 == res) printf("%ld %ld\n", ts.tv_sec, ts.tv_nsec); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment