#include #include #include #include #include #include #include #include #include int main() { unsigned long max = 1UL; int semId; semId = semget(IPC_PRIVATE, 1, 00600); semctl(semId, 0, SETVAL, 1); struct sembuf unlock = {0, 1, SEM_UNDO}; for (max = 1UL; max < 33366475776UL; max++) { // Incrementing semaphore. if (semop(semId, &unlock, 1) < 0) { printf("Max semaphore value: %lu\n", max); // Flagging semaphore for deletion. if (semctl(semId, 0, IPC_RMID) < 0) { perror("can't deallocate\n"); exit(1); } exit(1); } } semctl(semId, 0, IPC_RMID); return 0; }