Summary Files Commits Branches @commit @diff @stats
path: root / Year 3 / System programming / Practice09 / ex5-2.c
blob: 1b5c83c391497a7a02d28fe05d4f54c2075bfcc6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <mqueue.h>

#include "ex5.h"

int main(int argc, char* argv[]) {
	mqd_t mq = mq_open(queueName, O_RDONLY);

	char buf[64];
	while (1) {
		mq_receive(mq, buf, 64, NULL);
		if (buf[0] == '\0') break;
		write(1, buf, strlen(buf));
	}

	mq_close(mq);
	mq_unlink(queueName);
	return 0;
}