Summary Files Commits Branches @commit @diff @stats
path: root / Year 3 / System programming / Practice09 / ex2.c
blob: 20c0c109d32de7643401cff1ec93aecca6c80f61 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <fcntl.h>
#include <sys/stat.h>
#include <mqueue.h>
#include <stdio.h>
#include <string.h>

int main() {
	struct mq_attr mqattrs = {
		.mq_maxmsg = 5,
		.mq_msgsize = 1024,
	};
	mqd_t mq = mq_open("/spqueue", O_RDWR | O_CREAT, 0700, &mqattrs);

	char msg[] = "hello world";
	mq_send(mq, msg, strlen(msg), 0);

	char rmsg[1024] = { '\0' };
	mq_receive(mq, rmsg, 1024, NULL);

	printf("%s\n", rmsg);

	mq_close(mq);
	mq_unlink("/spqueue");

	return 0;
}