1 /*
2 * Copyright (c) International Business Machines Corp., 2001
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
12 * the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program.
16 *
17 * History
18 * 07/2001 John George
19 * -Ported
20 * 04/2002 wjhuie sigset cleanups
21 */
22
23 /*
24 * DESCRIPTION
25 * Tests to see if pids returned from fork and waitpid are same.
26 *
27 * ALGORITHM
28 * Check proper functioning of waitpid with pid = -1 and arg = WNOHANG
29 */
30
31 #include "waitpid_common.h"
32
do_child_1(void)33 static void do_child_1(void)
34 {
35 pid_t pid;
36 int i;
37 int status;
38
39 for (i = 0; i < MAXKIDS; i++) {
40 if (i == (MAXKIDS / 2))
41 SAFE_SETPGID(0, 0);
42
43 pid = SAFE_FORK();
44 if (pid == 0)
45 do_exit(0);
46
47 fork_kid_pid[i] = pid;
48 }
49
50 /* Check that waitpid with WNOHANG returns zero */
51 if (TST_TRACE(waitpid_ret_test(-1, &status, WNOHANG, 0, 0)))
52 return;
53
54 TST_CHECKPOINT_WAKE2(0, MAXKIDS);
55
56 if (TST_TRACE(reap_children(-1, WNOHANG, fork_kid_pid, MAXKIDS)))
57 return;
58
59 tst_res(TPASS, "Test PASSED");
60 }
61
62 static struct tst_test test = {
63 .forks_child = 1,
64 .needs_checkpoints = 1,
65 .setup = waitpid_setup,
66 .cleanup = waitpid_cleanup,
67 .test_all = waitpid_test,
68 };
69