1#include <errno.h> 2#include <stdio.h> 3#include <stdlib.h> 4#include <string.h> 5#include <unistd.h> 6 7#include <OS.h> 8 9 10static void 11list_semaphores(const char* process) 12{ 13 printf("%s (%ld) semaphores:\n", process, find_thread(NULL)); 14 15 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}