1/* Example of using sigaction() to setup a signal handler with 3 arguments
2 * including siginfo_t.
3 */
4#include <stdio.h>
5#include <unistd.h>
6#include <signal.h>
7#include <string.h>
8
9static void hdl (int sig, siginfo_t *siginfo, void *context)
10{
11 printf ("Sending PID: %ld, UID: %ld\n",
12 (long)siginfo->si_pid, (long)siginfo->si_uid);
13}
14
15int main (int argc, char *argv[])
16{
17 struct sigaction act;
18
19 memset (&act, '\0', sizeof(act));
20
21 /* Use the sa_sigaction field because the handles has two additional parameters */
22 act.sa_sigaction = &hdl;
23
24 /* The SA_SIGINFO flag tells sigaction() to use the sa_sigaction field, not sa_handler. */
25 act.sa_flags = SA_SIGINFO;
26
27 if (sigaction(SIGTERM, &act, NULL) < 0) {
28 perror ("sigaction");
29 return 1;
30 }
31
32 while (1)
33 sleep (10);
34
35 return 0;
36}