Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <string.h>
- #include <stdlib.h>
- #include <sys/ipc.h>
- #include <sys/msg.h>
- #define MSGSIZE 100
- #define MSGTYPE1 1
- #define MSGTYPE2 2
- #define MSGTYPE3 3
- #define ALLTYPES 0
- typedef struct message
- {
- long mtype;
- char mtext[MSGSIZE];
- } message;
- void sendFinal(int queue)
- {
- message buf = {MSGTYPE3, ""};
- msgsnd(queue, &buf, 0, 0);
- }
- void recvm(int queue)
- {
- message msg;
- ssize_t code;
- while ((code = msgrcv(queue, &msg, MSGSIZE, 0, MSG_NOERROR)) > 0)
- {
- if (msg.mtype == MSGTYPE2)
- break;
- printf("msg: %s\n", msg.mtext);
- }
- }
- int main()
- {
- int queue;
- queue = msgget(123, IPC_CREAT);
- printf("Connected\n");
- recvm(queue);
- sendFinal(queue);
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement