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

27
main.c
View file

@ -1,10 +1,25 @@
#include <stdio.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[]) {
printf("Hello, World!");
#ifdef DEBUG
printf("DEBUG is defined");
#endif
return 0;
signal(SIGINT, intHandler);
printf("Hello, World!\n");
#ifdef DEBUG
printf("DEBUG is defined\n");
#endif
while (keepRunning) {
printf("runing!\n");
sleep(1);
}
return 0;
}