Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/msg.h>
- #include <stdio.h>
- struct my_msg {
- long mtype;
- struct msg_inf {
- char src[24];
- char msg[512];
- } msg;
- };
- int main () {
- key_t key;
- int mqid;
- size_t msg_size;
- msg_size = sizeof(struct my_msg) - sizeof(long);
- key = ftok("/tmp/ssd", 'b');
- printf("K0\t%02x\t%s\t%d\n", key, "/tmp/ssd", 'b');
- key = ftok("/tmp/msg", 'a');
- printf("K\t%02x\t%s\t%d\n", key, "/tmp/msg", 'a');
- mqid = msgget(key, 0666 | IPC_CREAT);
- struct my_msg msg = {2, {"system", "Horrrrrry"}};
- struct my_msg rmsg;
- msgsnd(mqid, &msg, msg_size, 0);
- // rcv
- printf("RET\t%ld\n", msgrcv(mqid, &rmsg, msg_size, 2, 0));
- // print
- printf("R\tmtype\t%ld\n", rmsg.mtype);
- printf("R\tsrc\t\"%s\"\n", rmsg.msg.src);
- printf("R\tmsg\t\"%s\"\n", rmsg.msg.msg);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement