Last active
May 15, 2019 09:03
-
-
Save ph1ee/05d641faf7fb5ef9f10207392c743ec9 to your computer and use it in GitHub Desktop.
print time periodically
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
#define _DEFAULT_SOURCE | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#include <unistd.h> | |
int main(int argc, char *argv[]) { | |
char outstr[200]; | |
int usec = 100; | |
if (argc > 1) { | |
usec = atoi(argv[1]); | |
} | |
while (usec < 0 || usleep(usec) == 0) { | |
time_t t = time(NULL); | |
struct tm *tmp = localtime(&t); | |
if (tmp == NULL) { | |
perror("localtime"); | |
exit(EXIT_FAILURE); | |
} | |
if (strftime(outstr, sizeof(outstr), "%T", tmp)) { | |
fprintf(stdout, "%s\n", outstr); | |
} | |
} | |
exit(EXIT_FAILURE); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment