Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
26 lines (22 sloc) 471 Bytes
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
static void handler(int);
int ctrl_c = 0;
int *ptr = (int*) &ctrl_c;
void main(void) {
if (signal(SIGINT, handler) == SIG_ERR)
printf( "Couldn't handle SIGINT.\n");
while (1) {
if (ctrl_c) {
printf("Ctrl+C is pressed\n");
}
sleep(1);
}
}
static void handler(int signum) {
printf("key is pressed\n");
*ptr = 1;
return;
}
You can’t perform that action at this time.