. use library function to parse memory string
[minix3.git] / test / select / test13a.c
blob9b76bd80178008e2c257aeb2f74467f6a7f38172
1 /*
2 * Test name: test13a.c
4 * Objective: The purpose of this tests is to show how a select can
5 * get into a race condition when dealing with signals.
6 *
7 * Description: The program waits for SIGHUP or input in the terminal
8 */
10 #include <sys/types.h>
11 #include <sys/select.h>
12 #include <stdlib.h>
13 #include <unistd.h>
14 #include <time.h>
15 #include <stdio.h>
16 #include <signal.h>
17 #include <errno.h>
19 int got_sighup = 0;
21 void catch_hup(int sig_num)
23 printf("Received a SIGHUP, set global vble \n");
24 got_sighup = 1;
27 int main(void) {
28 int ret; /* return value */
29 fd_set read_fds;
30 char data[1024];
32 /* Init read fd_set */
33 FD_ZERO(&read_fds);
34 FD_SET(0, &read_fds);
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");
46 sleep(5);
48 printf("Blocking now on select...\n");
49 ret = select(1, &read_fds, NULL, NULL, NULL);
50 if (got_sighup) {
51 printf("We have a sighup signal so exit the program\n");
52 exit(0);
54 gets(data);
55 printf("Got entry for terminal then, bye\n");