feat(main): add SIGINT detect

This commit is contained in:
iridiumR 2022-09-18 11:24:31 +08:00
parent 69229a3285
commit 88cabfb434
No known key found for this signature in database
GPG key ID: 5574BE4450D55618

21
main.c
View file

@ -1,10 +1,25 @@
#include <stdio.h>
#include <signal.h> #include <signal.h>
#include <stdio.h>
#include <unistd.h>
static volatile int keepRunning = 1;
void intHandler(int dummy) {
printf("\nend!\n");
keepRunning = 0;
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
printf("Hello, World!");
signal(SIGINT, intHandler);
printf("Hello, World!\n");
#ifdef DEBUG #ifdef DEBUG
printf("DEBUG is defined"); printf("DEBUG is defined\n");
#endif #endif
while (keepRunning) {
printf("runing!\n");
sleep(1);
}
return 0; return 0;
} }