34 lines
770 B
C
34 lines
770 B
C
#include <sys/time.h>
|
|
#include <unistd.h>
|
|
#include <signal.h>
|
|
#include <assert.h>
|
|
#include <errno.h>
|
|
#include <stdio.h>
|
|
|
|
static void silence_sigint(int signum) {}
|
|
|
|
int main(int argc, const char **argv) {
|
|
signal(silence_sigint, SIGINT);
|
|
struct timespec duration;
|
|
struct timespec remaining;
|
|
|
|
while (1) {
|
|
duration.tv_sec = 3;
|
|
duration.tv_nsec = 0;
|
|
|
|
int result = nanosleep(&duration, &remaining);
|
|
|
|
if (result != 0) {
|
|
assert(errno == EINTR);
|
|
printf(
|
|
"EINTR: remaining: sec=%lu, nsec=%u\n",
|
|
(unsigned long) remaining.tv_sec,
|
|
(unsigned int) remaining.tv_nsec
|
|
);
|
|
} else {
|
|
printf("NO EINTR\n");
|
|
}
|
|
}
|
|
return 0;
|
|
}
|