Advertisement
jfcmacro

Untitled

Mar 12th, 2019
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 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.   for (;;) {
  30.     struct sembuf op[1];
  31.  
  32.     op[0].sem_num = 0;
  33.     op[0].sem_op = -1;
  34.     op[0].sem_flg = 0;
  35.  
  36.     cout << "Esperando para imprimir" << endl;
  37.     semop(semid, op, 1);
  38.     cout << "Impresion lista" << endl;
  39.   }
  40.  
  41.   return EXIT_SUCCESS;
  42. }
  43.  
  44. static void usage(const char *progname) {
  45.   cerr << "Uso: " << progname << " <semkey> "
  46.        << endl;
  47.   exit(EXIT_FAILURE);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement