...
Code Block | ||
---|---|---|
| ||
#include <signal.h> #include <stdio.h> #include <stdlib.h> enum { MAXLINE = 1024 }; char *info = NULL; void log_message(void) { fprintf(stderr, info); } void handler(int signum) { log_message(); free(info); info = NULL; } int main(void) { if (signal(SIGINT, handler);) == SIG_ERR) { /* handle error */ } info = (char*)malloc(MAXLINE); if (info == NULL) { /* Handle Error */ } while (1) { /* main loop program code */ log_message(); /* more program code */ } return 0; } |
...
Code Block | ||
---|---|---|
| ||
#include <signal.h> #include <stdio.h> #include <stdlib.h> enum { MAXLINE = 1024 }; volatile sig_atomic_t eflag = 0; char *info = NULL; void log_message(void) { fprintf(stderr, info); } void handler(int signum) { eflag = 1; } int main(void) { if (signal(SIGINT, handler);) == SIG_ERR) { /* handle error */ } info = (char*)malloc(MAXLINE); if (info == NULL) { /* Handle Error */ } while (!eflag) { /* main loop program code */ log_message(); /* more program code */ } log_message(); free(info); info = NULL; return 0; } |
...