183098Smp#include <errno.h>
283098Smp#include <stdio.h>
383098Smp#include <stdlib.h>
483098Smp#include <string.h>
583098Smp#include <unistd.h>
6231990Smp
7231990Smp#include <OS.h>
8231990Smp
9231990Smp
1083098Smpstatic void
11231990Smplist_semaphores(const char* process)
12231990Smp{
13231990Smp	printf("%s (%ld) semaphores:\n", process, find_thread(NULL));
14231990Smp
1583098Smp	sem_info semInfo;
16	int32 cookie = 0;
17	while (get_next_sem_info(B_CURRENT_TEAM, &cookie, &semInfo) == B_OK)
18		printf("  %9ld  %s\n", semInfo.sem, semInfo.name);
19}
20
21
22int
23main()
24{
25	pid_t child = fork();
26	if (child < 0) {
27		fprintf(stderr, "Error: fork() failed: %s\n", strerror(errno));
28		exit(1);
29	}
30
31	if (child > 0) {
32		// the parent process -- wait for the child to finish
33		status_t result;
34		wait_for_thread(child, &result);
35	}
36
37	list_semaphores(child == 0 ? "child" : "parent");
38
39	return 0;
40}