Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sys/types.h>
- #include <sys/ipc.h>
- #include <sys/sem.h>
- #include <cstdlib>
- #include <cstring>
- #include <errno.h>
- using namespace std;
- static void usage(const char *progname);
- int
- main(int argc, char *argv[]) {
- if (argc != 2)
- usage(argv[0]);
- int key = atoi(argv[1]);
- int semid = semget(key, 1, 0660 );
- if (semid == -1) {
- cerr << "Error abrir el semaforo: " <<
- strerror(errno) << endl;
- return EXIT_FAILURE;
- }
- for (;;) {
- struct sembuf op[1];
- op[0].sem_num = 0;
- op[0].sem_op = -1;
- op[0].sem_flg = 0;
- cout << "Esperando para imprimir" << endl;
- semop(semid, op, 1);
- cout << "Impresion lista" << endl;
- }
- return EXIT_SUCCESS;
- }
- static void usage(const char *progname) {
- cerr << "Uso: " << progname << " <semkey> "
- << endl;
- exit(EXIT_FAILURE);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement