Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<sys/mman.h>
- #include<sys/stat.h>
- #include<fcntl.h>
- #include<unistd.h>
- #include<sys/types.h>
- #include <sys/stat.h>
- #include <sys/wait.h>
- #include <time.h>
- #include <math.h>
- #include <string.h>
- #include <mqueue.h>
- #include <semaphore.h>
- #define SEM2 "/sem2"
- #define MAXTAM 2096
- typedef struct {
- int valor;
- char aviso[80];
- } Mensaje;
- int main(int argc, char** argv) {
- struct mq_attr attributes = {
- .mq_flags = 0,
- .mq_maxmsg = 10,
- .mq_curmsgs = 0,
- .mq_msgsize = sizeof (Mensaje)
- };
- char nombreColaRec[80];
- char nombreColaEnv[80];
- sem_t *sem2;
- if ((sem2 = sem_open(SEM2, O_EXCL)) == SEM_FAILED) {
- perror("sem_open");
- exit(EXIT_FAILURE);
- }
- strcpy(nombreColaRec, argv[1]);
- strcpy(nombreColaEnv, argv[2]);
- Mensaje msg;
- int i = 0;
- mqd_t queue = mq_open(nombreColaRec, O_CREAT | O_RDONLY, S_IRUSR | S_IWUSR, &attributes);
- if (queue == (mqd_t) - 1) {
- fprintf(stderr, "Error opening the queue\n");
- return EXIT_FAILURE;
- }
- if (mq_receive(queue, (char *) &msg, sizeof (msg), NULL) == -1) {
- fprintf(stderr, "Error sending message\n");
- return EXIT_FAILURE;
- }
- printf("Cadena a convertir: %s\n", msg.aviso);
- while (msg.aviso[i] != '\0') {
- if (msg.aviso[i] != ' ') {
- msg.aviso[i]++;
- }
- i++;
- }
- mqd_t queue2 = mq_open(nombreColaEnv, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR, &attributes);
- if (queue == (mqd_t) - 1) {
- fprintf(stderr, "Error opening the queue\n");
- return EXIT_FAILURE;
- }
- if (mq_send(queue2, (char *) &msg, sizeof (msg), 1) == -1) {
- fprintf(stderr, "Error sending message\n");
- return EXIT_FAILURE;
- }
- sem_post(sem2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement