4 * Objective: The purpose of this tests is to show how a select can
5 * get into a race condition when dealing with signals.
7 * Description: The program waits for SIGHUP or input in the terminal
10 #include <sys/types.h>
11 #include <sys/select.h>
21 void catch_hup(int sig_num
)
23 printf("Received a SIGHUP, set global vble \n");
28 int ret
; /* return value */
32 /* Init read fd_set */
36 /* set the HUP signal handler to 'catch_hup' */
37 signal(SIGHUP
, catch_hup
);
39 /* Get proc_id and print it */
40 printf("Send a signal from other terminal with: kill -1 %d\n", getpid());
41 printf("Going to sleep for 5 seconds, if the signal arrives meanwhile\n");
42 printf("the process will be blocked until there is input in the keyboard\n");
43 printf("if the signal arrives after the timeout and while in select, it will\n");
44 printf("behave as it should.\n");
45 printf("Sleeping for 5 secs\n");
48 printf("Blocking now on select...\n");
49 ret
= select(1, &read_fds
, NULL
, NULL
, NULL
);
51 printf("We have a sighup signal so exit the program\n");
55 printf("Got entry for terminal then, bye\n");