Skip to content

Instantly share code, notes, and snippets.

@kostikbel
Created March 7, 2021 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kostikbel/12332ccd0876d9d95264e6e434549585 to your computer and use it in GitHub Desktop.
Save kostikbel/12332ccd0876d9d95264e6e434549585 to your computer and use it in GitHub Desktop.
#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);
}
int
main(void)
{
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)
pause();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment