Linux Signals


Signals

/* Program to  perform operations depending on external signals */

#include<stdlib.h>
#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
#include<signal.h>
int a,b;
void division(int sig)
{
int c=0;
c = a/b;
printf(“\n\t QUOTIENT = %d”,c);
printf(“\tSignal = %d\n”,sig);
(void)signal(SIGINT,SIG_DFL);
}
void mul(int sig)
{
int c=0;
c = a*b;
printf(“\n\t PRODUCT = %d”,c);
printf(“\tSignal = %d\n”,sig);
(void)signal(SIGINT,division);
}
void sub(int sig)
{
int c=0;
c = a-b;
printf(“\n\t DIFFERENCE = %d”,c);
printf(“\tSignal = %d\n”,sig);
(void)signal(SIGINT,mul);
}

void add(int sig)
{
int c=0;
c= a+b;
printf(“\n\t SUM = %d”,c);
printf(“\tSignal = %d\n”,sig);
(void)signal(SIGINT,sub);
}
int main()
{
printf(“\n\t Enter first no. : “);
scanf(“%d”,&a);
printf(“\n\t Enter second no. : “);
scanf(“%d”,&b);
(void)signal(SIGINT,add);
while(1){sleep(1);}
return 0;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s