18 int is
, array
[4], parsigs
, parcum
, sigct
, cumsig
, subtest
;
19 int iteration
, kk
= 0;
23 int main(int argc
, char *argv
[]);
41 for (i
= 0; i
< ITERATIONS
; i
++) {
43 if (m
& 0001) test2a();
44 if (m
& 0002) test2b();
45 if (m
& 0004) test2c();
46 if (m
& 0010) test2d();
47 if (m
& 0020) test2e();
48 if (m
& 0040) test2f();
49 if (m
& 0100) test2g();
52 if (cumsig
!= ITERATIONS
) e(101);
54 return(-1); /* impossible */
66 printf("pipe error. errno= %d\n", errno
);
72 printf("fork failed\n");
79 for (i
= 0; i
< 2048; i
++) buf
[i
] = i
& 0377;
80 for (q
= 0; q
< 8; q
++) {
81 if (write(fd
[1], buf
, 2048) < 0) {
82 printf("write pipe err. errno=%d\n", errno
);
90 printf("wrong exit code %d\n", q
);
97 for (q
= 0; q
< 32; q
++) {
98 n
= read(fd
[0], buf
, 512);
100 printf("read yielded %d bytes, not 512\n", n
);
104 for (j
= 0; j
< n
; j
++)
105 if ((buf
[j
] & 0377) != (kk
& 0377)) {
106 printf("wrong data: %d %d %d \n ",
107 j
, buf
[j
] & 0377, kk
& 0377);
123 signal(SIGPIPE
, sigpip
);
129 write(fd
[1], buf
, 1);
145 signal(SIGINT
, SIG_DFL
);
147 if ((array
[is
++] = fork()) > 0) {
148 if ((array
[is
++] = fork()) > 0) {
149 if ((array
[is
++] = fork()) > 0) {
150 if ((array
[is
++] = fork()) > 0) {
151 signal(SIGINT
, SIG_IGN
);
152 kill(array
[0], SIGINT
);
153 kill(array
[1], SIGINT
);
154 kill(array
[2], SIGINT
);
155 kill(array
[3], SIGINT
);
177 int pid
, stat_loc
, s
;
182 /* Test waitpid(pid, arg2, 0) */
187 s
= waitpid(pid
, &stat_loc
, 0);
189 if (WIFEXITED(stat_loc
) == 0) e(3);
190 if (WIFSIGNALED(stat_loc
) != 0) e(4);
191 if (WEXITSTATUS(stat_loc
) != 22) e(5);
197 /* Test waitpid(-1, arg2, 0) */
202 s
= waitpid(-1, &stat_loc
, 0);
204 if (WIFEXITED(stat_loc
) == 0) e(8);
205 if (WIFSIGNALED(stat_loc
) != 0) e(9);
206 if (WEXITSTATUS(stat_loc
) != 33) e(10);
212 /* Test waitpid(0, arg2, 0) */
217 s
= waitpid(0, &stat_loc
, 0);
219 if (WIFEXITED(stat_loc
) == 0) e(13);
220 if (WIFSIGNALED(stat_loc
) != 0) e(14);
221 if (WEXITSTATUS(stat_loc
) != 44) e(15);
227 /* Test waitpid(0, arg2, WNOHANG) */
228 signal(SIGTERM
, SIG_DFL
);
233 s
= waitpid(0, &stat_loc
, WNOHANG
);
235 if (kill(pid
, SIGTERM
) != 0) e(18);
236 if (waitpid(pid
, &stat_loc
, 0) != pid
) e(19);
237 if (WIFEXITED(stat_loc
) != 0) e(20);
238 if (WIFSIGNALED(stat_loc
) == 0) e(21);
239 if (WTERMSIG(stat_loc
) != SIGTERM
) e(22);
245 /* Test some error conditions. */
247 if (waitpid(0, &stat_loc
, 0) != -1) e(23);
248 if (errno
!= ECHILD
) e(24);
250 if (waitpid(0, &stat_loc
, WNOHANG
) != -1) e(25);
251 if (errno
!= ECHILD
) e(26);
257 int pid1
, pid2
, stat_loc
, s
;
259 /* Test waitpid with two children. */
261 if (iteration
> 1) return; /* slow test, don't do it too much */
262 if ( (pid1
= fork())) {
264 if ( (pid2
= fork()) ) {
265 /* Parent. Collect second child first. */
266 s
= waitpid(pid2
, &stat_loc
, 0);
268 if (WIFEXITED(stat_loc
) == 0) e(2);
269 if (WIFSIGNALED(stat_loc
) != 0) e(3);
270 if (WEXITSTATUS(stat_loc
) != 222) e(4);
272 /* Now collect first child. */
273 s
= waitpid(pid1
, &stat_loc
, 0);
275 if (WIFEXITED(stat_loc
) == 0) e(6);
276 if (WIFSIGNALED(stat_loc
) != 0) e(7);
277 if (WEXITSTATUS(stat_loc
) != 111) e(8);
280 sleep(2); /* child 2 delays before exiting. */
285 exit(111); /* child 1 exits immediately */
292 /* test getpid, getppid, getuid, etc. */
294 pid_t pid
, pid1
, ppid
, cpid
, stat_loc
, err
;
300 if ( (pid1
= fork())) {
301 /* Parent. Do nothing. */
302 if (wait(&stat_loc
) != pid1
) e(1);
303 if (WEXITSTATUS(stat_loc
) != (pid1
& 0377)) e(2);
305 /* Child. Get ppid. */
308 if (ppid
!= pid
) err
= 3;
309 if (cpid
== ppid
) err
= 4;
312 if (err
!= 0) e(err
);
317 /* test time(), times() */
327 clocks_per_sec
= sysconf(_SC_CLK_TCK
);
333 if (t1
< 650000000L) e(1); /* 650000000 is Sept. 1990 */
336 t1
= time( (time_t *) NULL
);
337 if (t1
< 650000000L) e(3);
340 t2
= time( (time_t *) NULL
);
342 if (t2
- t1
< 1) e(5);
346 if (t4
== (clock_t) -1) e(6);
347 if (t4
- t3
< clocks_per_sec
) e(7);
351 int s
; /* for ANSI */