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 *	fork02.c
23 *
24 * DESCRIPTION
25 *	Test correct operation of fork:
26 *		pid == 0 in child;
27 *		pid > 0 in parent from wait;
28 *
29 * ALGORITHM
30 *	Fork one process, check for pid == 0 in child.
31 *	Check for pid > 0 in parent after wait.
32 *
33 * USAGE
34 *	fork02
35 *
36 * HISTORY
37 *	07/2001 Ported by Wayne Boyer
38 *
39 * RESTRICTIONS
40 *	None
41 */
42
43#include <sys/types.h>
44#include <sys/wait.h>
45#include <stdio.h>
46#include <unistd.h>
47#include "test.h"
48
49static void setup(void);
50static void cleanup(void);
51
52char *TCID = "fork02";
53int TST_TOTAL = 1;
54
55int main(int ac, char **av)
56{
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
68		pid1 = fork();
69		if (pid1 == -1)
70			tst_brkm(TBROK, cleanup, "fork() failed");
71
72		if (pid1 == 0) {
73			tst_resm(TINFO, "Inside child");
74			_exit(0);
75		} else {
76			tst_resm(TINFO, "Inside parent");
77			pid2 = wait(&status);
78			tst_resm(TINFO, "exit status of wait %d", status);
79
80			if (pid1 == pid2)
81				tst_resm(TPASS, "test 1 PASSED");
82			else
83				tst_resm(TFAIL, "test 1 FAILED");
84		}
85	}
86
87	cleanup();
88	tst_exit();
89}
90
91static void setup(void)
92{
93	tst_sig(FORK, DEF_HANDLER, cleanup);
94	TEST_PAUSE;
95}
96
97static void cleanup(void)
98{
99}
100