blob: b41938b0613189c03843397db874bde09e066602 [file] [log] [blame]
sewardjde4a1d02002-03-22 01:27:54 +00001
2#include <signal.h>
3#include <stdio.h>
4#include <stdlib.h>
5#include <unistd.h>
6
7static struct sigaction oldChildHandlerData;
8
9void theHandler(int arg)
10{
11 printf("handled %d\n", arg);
12}
13
14void setupHandlers()
15{
16 struct sigaction act;
17 act.sa_handler=theHandler;
18 sigemptyset(&(act.sa_mask));
19 sigaddset(&(act.sa_mask), SIGCHLD);
20 // Make sure we don't block this signal. gdb tends to do that :-(
21 sigprocmask(SIG_UNBLOCK, &(act.sa_mask), 0);
22
23 act.sa_flags = SA_NOCLDSTOP;
24
25 // CC: take care of SunOS which automatically restarts interrupted system
26 // calls (and thus does not have SA_RESTART)
27
28#ifdef SA_RESTART
29 act.sa_flags |= SA_RESTART;
30#endif
31
32 sigaction( SIGCHLD, &act, &oldChildHandlerData );
33
34 act.sa_handler=SIG_IGN;
35 sigemptyset(&(act.sa_mask));
36 sigaddset(&(act.sa_mask), SIGPIPE);
37 act.sa_flags = 0;
38 sigaction( SIGPIPE, &act, 0L);
39}
40
41int main()
42{
43 int i;
44 char buffer[200];
45 setupHandlers();
46 FILE *p = popen("echo Hallo World", "r");
47 while (!feof(p)) {
48 int n = fread(buffer, 200, 1, p);
49 write(2, buffer, n);
50 }
51 fclose(p);
52 for (i = 0; i < 1000000; i++) ;
53 return 0;
54}