#include Home >
Article > Backend Development > Write a program in C that does not terminate when Ctrl+C is pressed In this problem we need to create a program that will not terminate when ctrl C is pressed. Instead it prints "Ctrl C cannot terminate program". For this, we can use signal processing. Pressing ctrl c creates signal SIGINT. To solve this problem, we will catch and handle this signal. Program showing the implementation of our solution: The above is the detailed content of Write a program in C that does not terminate when Ctrl+C is pressed. For more information, please follow other related articles on the PHP Chinese website!Write a program in C that does not terminate when Ctrl+C is pressed
Example
#include <stdio.h>
#include <signal.h>
void signalHandle(int sig_num) {
signal(SIGINT, signalHandle);
printf("</p><p> Ctrl + C cannot terminate the program</p><p>");
fflush(stdout);
}
int main (){
signal(SIGINT, signalHandle);
while(!0)
return 0;
}
Output
Ctrl + C cannot terminate the program