aboutsummaryrefslogtreecommitdiffstats
path: root/man2/timerfd_create.2
diff options
context:
space:
mode:
Diffstat (limited to 'man2/timerfd_create.2')
-rw-r--r--man2/timerfd_create.230
1 files changed, 15 insertions, 15 deletions
diff --git a/man2/timerfd_create.2 b/man2/timerfd_create.2
index 516e050b35..d68206b054 100644
--- a/man2/timerfd_create.2
+++ b/man2/timerfd_create.2
@@ -602,7 +602,7 @@ a.out 3 1 100
#include <sys/timerfd.h>
#include <time.h>
#include <unistd.h>
-
+\&
static void
print_elapsed_time(void)
{
@@ -610,16 +610,16 @@ print_elapsed_time(void)
static int first_call = 1;
struct timespec curr;
static struct timespec start;
-
+\&
if (first_call) {
first_call = 0;
if (clock_gettime(CLOCK_MONOTONIC, &start) == \-1)
err(EXIT_FAILURE, "clock_gettime");
}
-
+\&
if (clock_gettime(CLOCK_MONOTONIC, &curr) == \-1)
err(EXIT_FAILURE, "clock_gettime");
-
+\&
secs = curr.tv_sec \- start.tv_sec;
nsecs = curr.tv_nsec \- start.tv_nsec;
if (nsecs < 0) {
@@ -628,7 +628,7 @@ print_elapsed_time(void)
}
printf("%d.%03d: ", secs, (nsecs + 500000) / 1000000);
}
-
+\&
int
main(int argc, char *argv[])
{
@@ -637,19 +637,19 @@ main(int argc, char *argv[])
uint64_t exp, tot_exp, max_exp;
struct timespec now;
struct itimerspec new_value;
-
+\&
if (argc != 2 && argc != 4) {
fprintf(stderr, "%s init\-secs [interval\-secs max\-exp]\en",
argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
if (clock_gettime(CLOCK_REALTIME, &now) == \-1)
err(EXIT_FAILURE, "clock_gettime");
-
+\&
/* Create a CLOCK_REALTIME absolute timer with initial
expiration and interval as specified in command line. */
-
+\&
new_value.it_value.tv_sec = now.tv_sec + atoi(argv[1]);
new_value.it_value.tv_nsec = now.tv_nsec;
if (argc == 2) {
@@ -660,27 +660,27 @@ main(int argc, char *argv[])
max_exp = atoi(argv[3]);
}
new_value.it_interval.tv_nsec = 0;
-
+\&
fd = timerfd_create(CLOCK_REALTIME, 0);
if (fd == \-1)
err(EXIT_FAILURE, "timerfd_create");
-
+\&
if (timerfd_settime(fd, TFD_TIMER_ABSTIME, &new_value, NULL) == \-1)
err(EXIT_FAILURE, "timerfd_settime");
-
+\&
print_elapsed_time();
printf("timer started\en");
-
+\&
for (tot_exp = 0; tot_exp < max_exp;) {
s = read(fd, &exp, sizeof(uint64_t));
if (s != sizeof(uint64_t))
err(EXIT_FAILURE, "read");
-
+\&
tot_exp += exp;
print_elapsed_time();
printf("read: %" PRIu64 "; total=%" PRIu64 "\en", exp, tot_exp);
}
-
+\&
exit(EXIT_SUCCESS);
}
.EE