Alarm Example, Registering Signal Handlers Code in Linus Operating System

All QuestionsCategory: Operating SystemAlarm Example, Registering Signal Handlers Code in Linus Operating System
Anonymous asked 3 years ago
1 Answers
Anonymous answered 3 years ago

Registering Signal Handlers
 

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

void handler_for_alrm(int signo) {
printf("You can't interrupt me\n");
time_t t1;
time(&t1); //t1=time(NULL);
printf("Current time is %s\n", ctime(&t1);
alarm(1);
}

int main() {
  printf("Welcome,pid=%d\n", getpid());
  signal(AIGALRM, handler_for_alrm);
  alarm(5);
  while (1)
    pause();
  return 0;
}