18 int child_is_dead
= 0;
20 void dead_child(int n
);
45 foo
= a
* b
; /* 2.42 */
46 bar
= c
* d
; /* 14.52 */
51 foo
*= d
; /* 25.168 */
52 foo
/= e
; /* 4.5760 */
54 bar
*= b
; /* 29.524 */
55 bar
/= e
; /* 5.3680 */
69 if (fabs(foo
- (a
* b
)) > 0.0001) err(1);
70 if (fabs(bar
- (c
* d
)) > 0.0001) err(2);
73 void dead_child(int n
)
78 (void) n
; /* Avoid warning about unused parameter */
80 if (wait(&status
) == -1) err(1);
82 if (!WIFEXITED(status
)) {
86 errct
+= WEXITSTATUS(status
);
104 write(pipefdp
[1], buf
, 1);
106 /* Wait for parent to wake me up */
107 read(pipefdc
[0], buf
, 1);
121 sa
.sa_handler
= dead_child
;
123 if (sigaction(SIGCHLD
, &sa
, NULL
) == -1) err(1);
130 /* Wait for child to wake me up */
131 read(pipefdp
[0], buf
, 1);
136 write(pipefdc
[1], buf
, 1);
140 while(child_is_dead
== 0) { fflush(stdout
); } /* Busy wait */
152 if (pipe(pipefdc
) == -1) err(1);
153 if (pipe(pipefdp
) == -1) err(2);
166 return(0); /* Never reached */