feat(main): add SIGINT detect
This commit is contained in:
parent
69229a3285
commit
88cabfb434
1 changed files with 21 additions and 6 deletions
27
main.c
27
main.c
|
@ -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!");
|
|
||||||
#ifdef DEBUG
|
signal(SIGINT, intHandler);
|
||||||
printf("DEBUG is defined");
|
|
||||||
#endif
|
printf("Hello, World!\n");
|
||||||
return 0;
|
#ifdef DEBUG
|
||||||
|
printf("DEBUG is defined\n");
|
||||||
|
#endif
|
||||||
|
while (keepRunning) {
|
||||||
|
printf("runing!\n");
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in a new issue