Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/msg.h>
- #include <sys/types.h>
- #include <sys/ipc.h>
- #include <string.h>
- #define CLEF 20
- struct msgbuf {
- long mtype; //type
- int a;
- int b;
- double resultat;
- char operande[1];
- int quitter;
- };
- struct msgbuf msgp;
- int main(void)
- {
- int msqid;
- msqid = msgget((key_t)CLE, 0750+IPC_CREAT); //crea message
- printf("Link started !\n");
- //recevoir
- do
- {
- msgp.a = 0;
- msgp.b = 0;
- msgp.resultat = 0.;
- msgp.quitter = 0;
- msgrcv(msqid, &msgp, sizeof(msgp), 0, NULL);
- if(strcmp(msgp.operande, "+") == 0)
- {
- msgp.resultat = msgp.a + msgp.b;
- msgsnd(msqid, &msgp, sizeof(msgp), NULL);
- }
- else if (strcmp(msgp.operande, "-") == 0)
- {
- msgp.resultat = msgp.a - msgp.b;
- msgsnd(msqid, &msgp, sizeof(msgp), NULL);
- }
- }while(msgp.quitter == 0);
- msgctl(msqid, IPC_RMID, IPC_NOWAIT);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement