Interrupt Handling in C
Before you start: To learn how to compile a c programme in C click here or click here
The communication goes from hardware toward the processor ,it referred to as interrupt (signal in C)Hardware device save the information interrupt in stack. If this information is not fetch from stack immediately so then it lost. Interrupt handling is referred to signal handling.
Basic interrupt Handling in C
#include <stdio.h>
#include <signal.h>
void signalhand (int sig)
{
FILE *fp=fopen("C://signal.txt","a");
fprintf(fp,"\n Signal received");
fclose(fp);
}
int main()
{
signal (SIGINT, (void*) signalhand );
while(1)
{
printf("\n Infinite loop");
}
return 0;
}
if one process is processing another interrupt , then it deal with another interrupt when the current one process is complete
In above C program we create a infinite loop ,which can terminate by pressing the CTRL + C key combination. When you pressing the CTRL + C then keyboard informs the processor to interrupt generate in the program. the processor react with the interrupt the signal and running the or processing the another signal. we already register the signal handler i.e called interrupt generate by processor.
SIGINT function are used to register a signal handler. SIGINT is a macro used to generate interrupt in the program. when you pressing the CTRL+C it generate a interrupt ,it forwarded by processor to the program and the it tapped by signal handler function and perform a certain action .
No comments:
Post a Comment