Thursday, 4 December 2014

Program for sigalrm in UNIX Operating system


#include<stdio.h>
#include<stdlib.h>
#include<signal.h>
void isr(int n)
{
static int i=0;
printf("in ISR......\n");
if(++i==3)
exit(0);
alarm(2);
}
main()
{
printf("proces:%d\n",getpid());
//signal(SIGINT,SIG_DFL);
alarm(3);
signal(SIGALRM,isr);
printf("alarm is set....\n");
//printf("in infinite loop...\n");

while(1);
}
OutPut:
madan@madan-Lenovo-G570:~/madan/osconcepts$ cc ex40.c
madan@madan-Lenovo-G570:~/madan/osconcepts$ ./a.out
proces:5897
alarm is set....
in ISR......
in ISR......
in ISR......