4 * Objective: The purpose of this tests is to show how pselect()
5 * solves the situation shown in test13a.c
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 */
30 sigset_t sigmask
, orig_sigmask
;
33 /* Init read fd_set */
37 /* set the signal masks */
38 sigemptyset(&sigmask
);
39 sigaddset(&sigmask
, SIGHUP
);
40 sigprocmask( SIG_BLOCK
, &sigmask
, &orig_sigmask
);
42 /* set the HUP signal handler to 'catch_hup' */
43 signal(SIGHUP
, catch_hup
);
45 /* Get proc_id and print it */
46 printf("Send a signal from other terminal with: kill -1 %d\n", getpid());
47 printf("Going to sleep for 5 seconds, if the signal arrives meanwhile\n");
48 printf("the process will be blocked until there is input in the keyboard\n");
49 printf("if the signal arrives after the timeout and while in select, it will\n");
50 printf("behave as it should.\n");
51 printf("Sleeping for 5 secs\n");
54 printf("Blocking now on select...\n");
56 ret
= pselect(1, &read_fds
, NULL
, NULL
, NULL
, &orig_sigmask
);
61 printf("We have a sighup signal so exit the program\n");
65 printf("Got entry for terminal then, bye\n");