#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>

void timer_handler (int signum)
  {
  static int count = 0;
  printf ("Timer abgelaufen, Zähler: %d\n", ++count);
  }

int main(void)
  {
  struct sigaction sa;
  struct itimerval timer;

  /* Installiere timer_handler als Signal Handler fuer SIGVTALRM. */
  memset(&sa, 0, sizeof (sa));
  sigemptyset(&sa.sa_mask);
  sa.sa_handler = &timer_handler;
  sigaction(SIGVTALRM, &sa, NULL);

  /* Timer konfigurieren fuer 500 ms ... */
  timer.it_value.tv_sec = 0;
  timer.it_value.tv_usec = 500000;

  /* ... und alle 500 ms danach */
  timer.it_interval.tv_sec = 0;
  timer.it_interval.tv_usec = 500000;

  /* Timer starten */
  setitimer(ITIMER_VIRTUAL, &timer, NULL);

  /* Mach irgendwas Wichtiges */
  while(1);

  return 0;
  }