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