Skip to content

Instantly share code, notes, and snippets.

Created March 7, 2021 16:20
What would you like to do?
#include <sys/time.h>
#include <err.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
static void
sigalrm_handler(int sig __unused)
static const char msg[] = "SIGALRM\n";
write(STDOUT_FILENO, msg, sizeof(msg) - 1);
struct sigaction sa;
struct itimerval it;
int error;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = sigalrm_handler;
error = sigaction(SIGALRM, &sa, NULL);
if (error != 0)
err(1, "sigaction");
memset(&it, 0, sizeof(it));
it.it_value.tv_sec = 1;
it.it_interval.tv_sec = 1;
error = setitimer(ITIMER_REAL, &it, NULL);
if (error != 0)
err(1, "setitimer");
while (true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment