1 #define _POSIX_SOURCE 1
19 int child_is_dead
= 0;
21 void dead_child(int n
);
46 foo
= a
* b
; /* 2.42 */
47 bar
= c
* d
; /* 14.52 */
52 foo
*= d
; /* 25.168 */
53 foo
/= e
; /* 4.5760 */
55 bar
*= b
; /* 29.524 */
56 bar
/= e
; /* 5.3680 */
70 if (fabs(foo
- (a
* b
)) > 0.0001) err(1);
71 if (fabs(bar
- (c
* d
)) > 0.0001) err(2);
74 void dead_child(int n
)
79 (void) n
; /* Avoid warning about unused parameter */
81 if (wait(&status
) == -1) err(1);
83 if (!WIFEXITED(status
)) {
87 errct
+= WEXITSTATUS(status
);
105 write(pipefdp
[1], buf
, 1);
107 /* Wait for parent to wake me up */
108 read(pipefdc
[0], buf
, 1);
122 sa
.sa_handler
= dead_child
;
124 if (sigaction(SIGCHLD
, &sa
, NULL
) == -1) err(1);
131 /* Wait for child to wake me up */
132 read(pipefdp
[0], buf
, 1);
137 write(pipefdc
[1], buf
, 1);
141 while(child_is_dead
== 0) { fflush(stdout
); } /* Busy wait */
153 if (pipe(pipefdc
) == -1) err(1);
154 if (pipe(pipefdp
) == -1) err(2);
167 return(0); /* Never reached */