btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / tests / system / kernel / wait_test_3.cpp
blob444a1b4a84059e3bcf81777b0862dbe37bd5d78e
1 /*
2 * Copyright 2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
7 #include <errno.h>
8 #include <stdio.h>
9 #include <string.h>
10 #include <sys/wait.h>
11 #include <unistd.h>
14 /*!
15 waitpid() should wait only once.
19 int
20 child2()
22 printf("child 2 1. parent id = %ld\n", getppid());
23 sleep(2);
24 printf("child 2 2. parent id = %ld\n", getppid());
25 return 2;
29 //! exits before child 2
30 int
31 child1()
33 printf("child 1 process group: %ld\n", getpgrp());
35 pid_t child = fork();
36 if (child == 0)
37 return child2();
39 sleep(1);
40 return 1;
44 int
45 main()
47 printf("main process group: %ld\n", getpgrp());
48 pid_t child = fork();
49 if (child == 0)
50 return child1();
52 pid_t pid;
53 do {
54 int childStatus = -1;
55 pid = waitpid(0, &childStatus, 0);
56 printf("waitpid() returned %ld (%s), child status %d\n", pid, strerror(errno), childStatus);
57 } while (pid >= 0);
59 return 0;