Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rdemeter
GitHub Repository: rdemeter/so
Path: blob/master/lab5/client_mq.c
221 views
1
#include<stdio.h>
2
#include<stdlib.h>
3
#include<sys/stat.h>
4
#include<sys/types.h>
5
#include<mqueue.h>
6
#include<string.h>
7
8
#define QUEUE_NAME "/my_queue3"
9
#define NUMBER 1337
10
#define MAX_SIZE 1024
11
#define MSG_END "done"
12
/* descriptorul cozii de mesaje */
13
mqd_t q;
14
int main(int argc, char **argv)
15
{
16
char buf[MAX_SIZE];
17
if ((q = mq_open(QUEUE_NAME, O_WRONLY)) < 0)
18
{
19
perror("open():");
20
exit(-1);
21
}
22
snprintf(buf, MAX_SIZE, "%d", 1337);
23
if (mq_send(q, buf, strlen(buf), 0) < 0)
24
{
25
perror("send():");
26
exit(-1);
27
}
28
if (mq_send(q, MSG_END, strlen(MSG_END), 0) < 0)
29
{
30
perror("send2():");
31
exit(-1);
32
}
33
if (mq_close(q) < 0)
34
{
35
perror("close():");
36
exit(-1);
37
}
38
return 0;
39
}
40
41