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