16 int is
, array
[4], parsigs
, parcum
, sigct
, cumsig
, subtest
;
17 int iteration
, kk
= 0;
22 int main(int argc
, char *argv
[]);
40 for (i
= 0; i
< ITERATIONS
; i
++) {
42 if (m
& 0001) test2a();
43 if (m
& 0002) test2b();
44 if (m
& 0004) test2c();
45 if (m
& 0010) test2d();
46 if (m
& 0020) test2e();
47 if (m
& 0040) test2f();
48 if (m
& 0100) test2g();
51 if (cumsig
!= ITERATIONS
) e(101);
53 return(-1); /* impossible */
65 printf("pipe error. errno= %d\n", errno
);
71 printf("fork failed\n");
78 for (i
= 0; i
< 2048; i
++) buf
[i
] = i
& 0377;
79 for (q
= 0; q
< 8; q
++) {
80 if (write(fd
[1], buf
, 2048) < 0) {
81 printf("write pipe err. errno=%d\n", errno
);
89 printf("wrong exit code %d\n", q
);
96 for (q
= 0; q
< 32; q
++) {
97 n
= read(fd
[0], buf
, 512);
99 printf("read yielded %d bytes, not 512\n", n
);
103 for (j
= 0; j
< n
; j
++)
104 if ((buf
[j
] & 0377) != (kk
& 0377)) {
105 printf("wrong data: %d %d %d \n ",
106 j
, buf
[j
] & 0377, kk
& 0377);
122 signal(SIGPIPE
, sigpip
);
128 write(fd
[1], buf
, 1);
144 signal(SIGINT
, SIG_DFL
);
146 if ((array
[is
++] = fork()) > 0) {
147 if ((array
[is
++] = fork()) > 0) {
148 if ((array
[is
++] = fork()) > 0) {
149 if ((array
[is
++] = fork()) > 0) {
150 signal(SIGINT
, SIG_IGN
);
151 kill(array
[0], SIGINT
);
152 kill(array
[1], SIGINT
);
153 kill(array
[2], SIGINT
);
154 kill(array
[3], SIGINT
);
176 int pid
, stat_loc
, s
;
181 /* Test waitpid(pid, arg2, 0) */
186 s
= waitpid(pid
, &stat_loc
, 0);
188 if (WIFEXITED(stat_loc
) == 0) e(3);
189 if (WIFSIGNALED(stat_loc
) != 0) e(4);
190 if (WEXITSTATUS(stat_loc
) != 22) e(5);
196 /* Test waitpid(-1, arg2, 0) */
201 s
= waitpid(-1, &stat_loc
, 0);
203 if (WIFEXITED(stat_loc
) == 0) e(8);
204 if (WIFSIGNALED(stat_loc
) != 0) e(9);
205 if (WEXITSTATUS(stat_loc
) != 33) e(10);
211 /* Test waitpid(0, arg2, 0) */
216 s
= waitpid(0, &stat_loc
, 0);
218 if (WIFEXITED(stat_loc
) == 0) e(13);
219 if (WIFSIGNALED(stat_loc
) != 0) e(14);
220 if (WEXITSTATUS(stat_loc
) != 44) e(15);
226 /* Test waitpid(0, arg2, WNOHANG) */
227 signal(SIGTERM
, SIG_DFL
);
232 s
= waitpid(0, &stat_loc
, WNOHANG
);
234 if (kill(pid
, SIGTERM
) != 0) e(18);
235 if (waitpid(pid
, &stat_loc
, 0) != pid
) e(19);
236 if (WIFEXITED(stat_loc
) != 0) e(20);
237 if (WIFSIGNALED(stat_loc
) == 0) e(21);
238 if (WTERMSIG(stat_loc
) != SIGTERM
) e(22);
244 /* Test some error conditions. */
246 if (waitpid(0, &stat_loc
, 0) != -1) e(23);
247 if (errno
!= ECHILD
) e(24);
249 if (waitpid(0, &stat_loc
, WNOHANG
) != -1) e(25);
250 if (errno
!= ECHILD
) e(26);
256 int pid1
, pid2
, stat_loc
, s
;
258 /* Test waitpid with two children. */
260 if (iteration
> 1) return; /* slow test, don't do it too much */
261 if ( (pid1
= fork())) {
263 if ( (pid2
= fork()) ) {
264 /* Parent. Collect second child first. */
265 s
= waitpid(pid2
, &stat_loc
, 0);
267 if (WIFEXITED(stat_loc
) == 0) e(2);
268 if (WIFSIGNALED(stat_loc
) != 0) e(3);
269 if (WEXITSTATUS(stat_loc
) != 222) e(4);
271 /* Now collect first child. */
272 s
= waitpid(pid1
, &stat_loc
, 0);
274 if (WIFEXITED(stat_loc
) == 0) e(6);
275 if (WIFSIGNALED(stat_loc
) != 0) e(7);
276 if (WEXITSTATUS(stat_loc
) != 111) e(8);
279 sleep(2); /* child 2 delays before exiting. */
284 exit(111); /* child 1 exits immediately */
291 /* test getpid, getppid, getuid, etc. */
293 pid_t pid
, pid1
, ppid
, cpid
, stat_loc
, err
;
299 if ( (pid1
= fork())) {
300 /* Parent. Do nothing. */
301 if (wait(&stat_loc
) != pid1
) e(1);
302 if (WEXITSTATUS(stat_loc
) != (pid1
& 0377)) e(2);
304 /* Child. Get ppid. */
307 if (ppid
!= pid
) err
= 3;
308 if (cpid
== ppid
) err
= 4;
311 if (err
!= 0) e(err
);
316 /* test time(), times() */
329 if (t1
< 650000000L) e(1); /* 650000000 is Sept. 1990 */
332 t1
= time( (time_t *) NULL
);
333 if (t1
< 650000000L) e(3);
336 t2
= time( (time_t *) NULL
);
338 if (t2
- t1
< 1) e(5);
342 if ( t4
== (clock_t) -1) e(6);
343 if (t4
- t3
< CLOCKS_PER_SEC
) e(7);
344 if (tmsbuf
.tms_utime
< 0) e(8);
345 if (tmsbuf
.tms_stime
< 0) e(9);
346 if (tmsbuf
.tms_cutime
< 0) e(10);
347 if (tmsbuf
.tms_cstime
< 0) e(11);
351 int s
; /* for ANSI */