Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/ipc.h>
- #include <sys/msg.h>
- #include <sys/types.h>
- #include <string.h>
- struct msgbuf {
- long type;
- char mtext[50];
- };
- void send_message(int mqid, const char *message)
- {
- struct msgbuf buffer;
- buffer.type = 1; // Ustawia typ komunikatu na 1
- strncpy(buffer.mtext, message, sizeof(buffer.mtext));
- if (msgsnd(mqid, &buffer, sizeof(buffer.mtext), 0) < 0)
- perror("msgsnd");
- else
- printf("Wysłano komunikat: %s\n", buffer.mtext);
- }
- int main(void)
- {
- int key = ftok("/tmp", 8);
- if (key < 0)
- perror("ftok");
- int id = msgget(key, 0600 | IPC_CREAT | IPC_EXCL);
- if (id < 0)
- perror("msgget");
- send_message(id, "Hello, message!");
- if (msgctl(id, IPC_RMID, 0) < 0)
- perror("msgctl");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement