1 /*
2 *
3 * Copyright (c) International Business Machines Corp., 2001
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 /*
21 * NAME
22 * fork03.c
23 *
24 * DESCRIPTION
25 * Check that child can use a large text space and do a large
26 * number of operations.
27 *
28 * ALGORITHM
29 * Fork one process, check for pid == 0 in child.
30 * Check for pid > 0 in parent after wait.
31 *
32 * USAGE
33 * fork03
34 *
35 * HISTORY
36 * 07/2001 Ported by Wayne Boyer
37 *
38 * RESTRICTIONS
39 * None
40 */
41
42 #include <sys/types.h>
43 #include <sys/wait.h>
44 #include <stdio.h>
45 #include "test.h"
46
47 char *TCID = "fork03";
48 int TST_TOTAL = 1;
49
50 static void setup(void);
51 static void cleanup(void);
52
main(int ac,char ** av)53 int main(int ac, char **av)
54 {
55 float fl1, fl2;
56 int i;
57 int pid1, pid2, status;
58
59 int lc;
60
61 tst_parse_opts(ac, av, NULL, NULL);
62
63 setup();
64
65 for (lc = 0; TEST_LOOPING(lc); lc++) {
66 tst_count = 0;
67 pid1 = fork();
68 if (pid1 == -1)
69 tst_brkm(TBROK, cleanup, "fork() failed");
70
71 if (pid1 == 0) {
72 /* child uses some cpu cycles */
73 for (i = 1; i < 32767; i++) {
74 fl1 = 0.000001;
75 fl1 = fl2 = 0.000001;
76 fl1 = fl1 * 10.0;
77 fl2 = fl1 / 1.232323;
78 fl1 = fl2 - fl2;
79 fl1 = fl2;
80 }
81
82 /* Pid must always be zero in child */
83 if (pid1 != 0)
84 exit(1);
85 else
86 exit(0);
87 } else {
88 tst_resm(TINFO, "process id in parent of child from "
89 "fork : %d", pid1);
90 pid2 = wait(&status); /* wait for child */
91
92 if (pid1 != pid2) {
93 tst_resm(TFAIL, "pids don't match : %d vs %d",
94 pid1, pid2);
95 continue;
96 }
97
98 if ((status >> 8) != 0) {
99 tst_resm(TFAIL, "child exited with failure");
100 continue;
101 }
102
103 tst_resm(TPASS, "test 1 PASSED");
104 }
105 }
106
107 cleanup();
108 tst_exit();
109 }
110
setup(void)111 static void setup(void)
112 {
113 tst_sig(FORK, DEF_HANDLER, cleanup);
114 TEST_PAUSE;
115 }
116
cleanup(void)117 static void cleanup(void)
118 {
119 }
120