jfcmacro

Untitled

Mar 12th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <sys/types.h>
  3. #include <sys/ipc.h>
  4. #include <sys/sem.h>
  5. #include <cstdlib>
  6. #include <cstring>
  7. #include <errno.h>
  8.  
  9. using namespace std;
  10.  
  11. static void usage(const char *progname);
  12.  
  13. int
  14. main(int argc, char *argv[]) {
  15.  
  16.   if (argc != 2)
  17.     usage(argv[0]);
  18.  
  19.   int key = atoi(argv[1]);
  20.  
  21.   int semid = semget(key, 1, 0660 );
  22.  
  23.   if (semid == -1) {
  24.     cerr << "Error abrir el semaforo: " <<
  25.       strerror(errno) << endl;
  26.     return EXIT_FAILURE;
  27.   }
  28.  
  29.   struct sembuf op[1];
  30.  
  31.   op[0].sem_num = 0;
  32.   op[0].sem_op = 1;
  33.   op[0].sem_flg = 0;
  34.  
  35.   cout << "Enviando evento " << endl;
  36.   semop(semid, op, 1);
  37.  
  38.   return EXIT_SUCCESS;
  39. }
  40.  
  41. static void usage(const char *progname) {
  42.   cerr << "Uso: " << progname << " <semkey> "
  43.        << endl;
  44.   exit(EXIT_FAILURE);
  45. }
Advertisement
Add Comment
Please, Sign In to add comment