previous | start | next

Example

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>

void handler(int n)
{
  printf("I'm melting ....\n");
  exit(0);

}

int main(int argc, char* argv[])
{
  int n = 0;
  signal(SIGALRM, handler);
  alarm(2);

  while(1) {
    printf(".");
    if ( ++n % 30 == 0 ) {
      printf("\n%d ", n);
    }
  }

  return 0;
}
  1. How does this program terminate? or does it?
  2. Who sends the SIGALRM signal to this process?


previous | start | next