Update watch(1) to handle more accurate intervals
This commit is contained in:
parent
4cb108f557
commit
703e18185c
14
watch.c
14
watch.c
@ -1,4 +1,5 @@
|
|||||||
/* See LICENSE file for copyright and license details. */
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -15,14 +16,19 @@ int
|
|||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char cmd[BUFSIZ];
|
char cmd[BUFSIZ];
|
||||||
int i, interval = 2;
|
char *end;
|
||||||
|
useconds_t interval = 2 * 1E6;
|
||||||
|
float period;
|
||||||
|
int i;
|
||||||
|
|
||||||
ARGBEGIN {
|
ARGBEGIN {
|
||||||
case 't':
|
case 't':
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
/* Only whole seconds for now */
|
period = strtof(EARGF(usage()), &end);
|
||||||
interval = estrtol(EARGF(usage()), 10);
|
if (*end != '\0' || errno != 0)
|
||||||
|
eprintf("invalid interval\n");
|
||||||
|
interval = period * 1E6;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
@ -44,7 +50,7 @@ main(int argc, char *argv[])
|
|||||||
printf("\x1b[2J\x1b[H"); /* clear */
|
printf("\x1b[2J\x1b[H"); /* clear */
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
system(cmd);
|
system(cmd);
|
||||||
sleep(interval);
|
usleep(interval);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user