Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/shm.h>
- #include <unistd.h>
- #include <sys/stat.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <sys/types.h>
- #include <wait.h>
- #include <fcntl.h>
- #include<sys/ipc.h>
- struct mensaje
- {
- long Tipo_Mensaje;
- char texto_mensaje[512];
- } mensaje;
- int main ()
- {
- key_t Clave;
- int Id_Cola_Mensajes;
- int aux;
- int maxNum = 10;
- int pid1, pid2;
- int val;
- //mensaje Un_Mensaje;
- Clave = ftok ("/bin/ls", 33);
- if (Clave == -1)
- {
- printf("Error, no se consigue la clave\n");
- exit(EXIT_FAILURE);
- }
- Id_Cola_Mensajes = msgget (Clave, 0777 | IPC_CREAT);
- if (Id_Cola_Mensajes == -1)
- {
- printf("Error no se consigue ID\n");
- exit(EXIT_FAILURE);
- }
- pnt(mensaje.texto_mensaje, "0");
- val = atoi(mensaje.texto_mensaje);
- //mensaje.Tipo_Mensaje = 1;
- //mensaje.texto_mensaje = 0;
- printf("fin primera etapa\n");
- //struct mensaje buffer_mensaje;
- */
- pid1 = fork();
- if(pid1 == -1)
- {
- printf("ERROR\n");
- exit(EXIT_FAILURE);
- }
- if (pid1 == 0)
- {
- msgsnd (Id_Cola_Mensajes, (struct msgbuf *)&mensaje, 512, IPC_NOWAIT);
- msgrcv (Id_Cola_Mensajes, (struct msgbuf *)&mensaje, 512, 0, 0);
- //printf("HOLA ESTOY CORRIENDO EN HIJO UNOO\n");
- while (mensaje.texto_mensaje <= maxNum)
- {
- aux=mensaje.texto_mensaje;
- if ((aux%2) == 0)
- {
- aux++;
- if (aux <= maxNum)
- printf("%d\n", aux);
- mensaje.texto_mensaje = aux;
- }
- }
- exit(EXIT_SUCCESS);
- }
- else
- {
- pid2 = fork();
- if(pid2 == -1)
- {
- printf("ERROR\n");
- exit(EXIT_FAILURE);
- }
- if (pid2 == 0)
- {
- msgsnd (Id_Cola_Mensajes, (struct msgbuf *)&mensaje, sizeof(mensaje.texto_mensaje)+sizeof(mensaje.mensaje), IPC_NOWAIT);
- msgrcv (Id_Cola_Mensajes, (struct msgbuf *)&mensaje, sizeof(mensaje.texto_mensaje) + sizeof(mensaje.mensaje), 2, 0);
- // printf("HOLA ESTOY CORRIENDO EN HIJO DOS\n");
- while (*Memoria <= maxNum)
- {
- aux = mensaje.texto_mensaje;
- if ((aux%2) == 1)
- {
- aux++;
- if (aux <= maxNum)
- printf("%d\n", aux);
- mensaje.texto_mensaje = aux;
- }
- }
- exit(EXIT_SUCCESS);
- }
- //printf("HOLA ESTOY CORRIENDO ALFINAL\n");
- msgctl (Id_Cola_Mensajes, IPC_RMID, (struct msqid_ds *)NULL);
- exit(EXIT_SUCCESS);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement