1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <stdio.h> #include <semaphore.h> #include <sys/stat.h> #include <fcntl.h> int main() { sem_t* sem = sem_open("/sem", O_CREAT); int sval = 0; sem_getvalue(sem, &sval); printf("%d\n", sval); sem_close(sem); sem_unlink("/sem"); return 0; }