Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/ipc.h>
- #include <sys/msg.h>
- #include <errno.h>
- int main(int argc, char **argv)
- {
- key_t key = ftok("/tmp/msg.temp", 1);
- if (key == -1) {
- printf("key: -1"); return 1;
- }
- struct message {
- long mtype;
- char mtext[80];
- } Msg;
- int msgq = msgget(key, IPC_CREAT| 0666);
- if (-1 == msgq)
- {
- printf("msgq: -2");
- printf("%d", errno);
- return 2;
- }
- int r = msgrcv(msgq, &Msg, sizeof(Msg.mtext), 0, 0 );
- FILE *f = fopen("/home/box/message.txt", "w");
- fwrite(Msg.mtext, sizeof(char), r, f);
- fclose(f);
- msgctl(msgq, IPC_RMID, 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement