#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
void handler (int sig)
{
printf ("Got signal %d\n", sig);
}
int main (int argc, char *argv[])
{
struct sigaction act;
memset (&act, '\0', sizeof(act));
// Use the sa_sigaction field because
// the handler has two additional parameters
act.sa_handler = &handler;
if (sigaction(SIGHUP, &act, NULL) < 0) {
perror ("sigaction");
return EXIT_FAILURE;
}
if (sigaction(SIGTERM, &act, NULL) < 0) {
perror ("sigaction");
return EXIT_FAILURE;
}
while (1) sleep (10);
return EXIT_SUCCESS;
}
I am a bit confused about "&handler" . What does it mean here? I am new to signal and really hope someone can give me a hint on how it works. Any help would be appreciated. Thx