Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Write a program that does not terminate when Ctrl+C is pressed in C
In this problem, we have to create a program that does not terminate when ctrl+C is pressed. Instead, it prints
“Ctrl + C cannot terminate the program”.
For this, we can use signal handling. The signal SIGINT is created on pressing ctrl+c. To solve this problem, we will catch this signal and handle it.
Program to show the implementation of our solution,
Example
#include <stdio.h>
#include <signal.h>
void signalHandle(int sig_num) {
signal(SIGINT, signalHandle);
printf("
Ctrl + C cannot terminate the program
");
fflush(stdout);
}
int main (){
signal(SIGINT, signalHandle);
while(!0)
return 0;
}
Output
Ctrl + C cannot terminate the program
Advertisements