jfcmacro

crearSemNomPosix.cpp

Mar 14th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <fcntl.h>
  3. #include <sys/stat.h>
  4. #include <semaphore.h>
  5. #include <unistd.h>
  6. #include <cstdlib>
  7. #include <cstring>
  8. #include <cerrno>
  9.  
  10. using namespace std;
  11.  
  12. static void usage(char *progname);
  13.  
  14. int
  15. main(int argc, char *argv[]) {
  16.  
  17.   if (argc != 2) usage(argv[0]);
  18.  
  19.   sem_t *sem;
  20.  
  21.   if ((sem = sem_open(argv[1],
  22.               O_CREAT | O_EXCL,
  23.               0660,
  24.               0)) == SEM_FAILED) {
  25.     cerr << "Error creando el semaforo: " <<
  26.       strerror(errno) << endl;
  27.     return EXIT_FAILURE;
  28.   }
  29.  
  30.   sem_close(sem);
  31.  
  32.   return EXIT_SUCCESS;
  33. }
  34.  
  35. static void usage(char *progname) {
  36.   cerr << "Uso: " << progname
  37.        << " <nombresem> "
  38.        << endl;
  39.   exit(EXIT_FAILURE);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment