xref: /haiku/src/tests/system/kernel/wait_test_1.c (revision 56a16fd0f9dbdee3f62f30136b41ec06f950ed36)
1*56a16fd0SAxel Dörfler /*
2*56a16fd0SAxel Dörfler  * Copyright 2007, Jérôme Duval. All rights reserved.
3*56a16fd0SAxel Dörfler  * Distributed under the terms of the MIT License.
4*56a16fd0SAxel Dörfler  */
5*56a16fd0SAxel Dörfler 
6*56a16fd0SAxel Dörfler 
7*56a16fd0SAxel Dörfler #include <errno.h>
8*56a16fd0SAxel Dörfler #include <stdio.h>
9*56a16fd0SAxel Dörfler #include <string.h>
10*56a16fd0SAxel Dörfler #include <sys/wait.h>
11*56a16fd0SAxel Dörfler #include <unistd.h>
12*56a16fd0SAxel Dörfler 
13*56a16fd0SAxel Dörfler 
14*56a16fd0SAxel Dörfler /*!
15*56a16fd0SAxel Dörfler 	wait()/waitpid() should return -1 and set errno to ECHILD, since there
16*56a16fd0SAxel Dörfler 	are no children to wait for.
17*56a16fd0SAxel Dörfler */
18*56a16fd0SAxel Dörfler int
main()19*56a16fd0SAxel Dörfler main()
20*56a16fd0SAxel Dörfler {
21*56a16fd0SAxel Dörfler 	int childStatus;
22*56a16fd0SAxel Dörfler 	pid_t pid = wait(&childStatus);
23*56a16fd0SAxel Dörfler 	printf("wait() returned %ld (%s)\n", pid, strerror(errno));
24*56a16fd0SAxel Dörfler 
25*56a16fd0SAxel Dörfler 	pid = waitpid(-1, &childStatus, 0);
26*56a16fd0SAxel Dörfler 	printf("waitpid(-1, ...) returned %ld (%s)\n", pid, strerror(errno));
27*56a16fd0SAxel Dörfler 
28*56a16fd0SAxel Dörfler 	pid = waitpid(0, &childStatus, 0);
29*56a16fd0SAxel Dörfler 	printf("waitpid(0, ...) returned %ld (%s)\n", pid, strerror(errno));
30*56a16fd0SAxel Dörfler 
31*56a16fd0SAxel Dörfler 	pid = waitpid(getpgrp(), &childStatus, 0);
32*56a16fd0SAxel Dörfler 	printf("waitpid(%ld, ...) returned %ld (%s)\n", getpgrp(), pid, strerror(errno));
33*56a16fd0SAxel Dörfler 
34*56a16fd0SAxel Dörfler 	return 0;
35*56a16fd0SAxel Dörfler }
36*56a16fd0SAxel Dörfler 
37