Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. /*
  2. ** semrm.cpp -- removes a semaphore
  3. */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <errno.h>
  8. #include <sys/types.h>
  9. #include <sys/ipc.h>
  10. #include <sys/sem.h>
  11.  
  12. int main(void)
  13. {
  14. key_t key;
  15. int semid;
  16.  
  17. if ((key = ftok(".", 'J')) == -1) {
  18. perror("ftok");
  19. exit(1);
  20. }
  21.  
  22. /* grab the semaphore set created by seminit.c: */
  23. if ((semid = semget(key, 1, 0)) == -1) {
  24. perror("semget");
  25. exit(1);
  26. }
  27.  
  28. /* remove it: */
  29. if (semctl(semid, 0, IPC_RMID) == -1) {
  30. perror("semctl");
  31. exit(1);
  32. }
  33.  
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement