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; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 * 18 * 19 * NAME 20 * fork11.c 21 * 22 * DESCRIPTION 23 * Test that parent gets a pid from each child when doing wait 24 * 25 * ALGORITHM 26 * Fork NUMFORKS children that do nothing. 27 * 28 * USAGE 29 * fork11 30 * 31 * HISTORY 32 * 07/2001 Ported by Wayne Boyer 33 * 34 * RESTRICTIONS 35 * None 36 */ 37 38 #include <sys/types.h> 39 #include <sys/wait.h> 40 #include <stdio.h> 41 #include <errno.h> 42 #include "test.h" 43 44 char *TCID = "fork11"; 45 int TST_TOTAL = 1; 46 47 static void setup(void); 48 static void cleanup(void); 49 50 #define NUMFORKS 100 51 52 int main(int ac, char **av) 53 { 54 int i, pid, cpid, status; 55 int fail = 0; 56 int lc; 57 58 tst_parse_opts(ac, av, NULL, NULL); 59 60 setup(); 61 62 for (lc = 0; TEST_LOOPING(lc); lc++) { 63 tst_count = 0; 64 65 for (i = 0; i < NUMFORKS; i++) { 66 pid = fork(); 67 if (pid == 0) 68 exit(0); 69 70 if (pid > 0) { /* parent */ 71 cpid = wait(&status); 72 if (cpid != pid) 73 fail++; 74 } else { 75 fail++; 76 break; 77 } 78 } 79 if (fail) 80 tst_resm(TFAIL, "fork failed %d times", fail); 81 else 82 tst_resm(TPASS, "fork test passed, %d processes", i); 83 } 84 85 cleanup(); 86 tst_exit(); 87 } 88 89 static void setup(void) 90 { 91 tst_sig(FORK, DEF_HANDLER, cleanup); 92 TEST_PAUSE; 93 } 94 95 static void cleanup(void) 96 { 97 } 98