1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
static volatile sig_atomic_t srv_shutdown = 0;
static void signal_handler(int sig) {
// Cleanup and close up stuff here
srv_shutdown = 1;
}
int main()
{
struct sigaction act;
memset(&act, 0, sizeof(act));
act.sa_handler = signal_handler;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
sigaction(SIGINT, &act, NULL);
sigaction(SIGTERM, &act, NULL);
sigaction(SIGHUP, &act, NULL);
sigaction(SIGALRM, &act, NULL);
sigaction(SIGUSR1, &act, NULL);
while(!srv_shutdown)
{
printf("Program processing stuff here.\n");
sleep(1);
}
//close(ppipe);
return EXIT_SUCCESS;
} |
Partager