Created
July 8, 2022 17:00
-
-
Save iTrooz/55d6bf8d02f379fd713bdf3d0484db9f to your computer and use it in GitHub Desktop.
Linux XSI message Hello World (msgget msgsnd msgrcv)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <sys/msg.h> | |
int main(){ | |
char* buf = "Hello world !"; | |
unsigned long len = strlen(buf); | |
char* buf2 = alloca(len); | |
key_t key = ftok("/tmp", rand()%100); // I don't think it actually needs to be random | |
printf("key=%i\n", key); | |
int qid = msgget(key, IPC_CREAT|0600); | |
perror("msgget"); | |
printf("qid=%i\n", qid); | |
msgsnd(qid, buf, len, 0); | |
perror("msgsnd"); | |
msgrcv(qid, buf2, len, 0, 0); | |
perror("rcvsnd"); | |
printf("RCV=%s\n", buf2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output :