blob: 76e0a76bf8ee79c6934f08c66f66ee489da239b9 (
plain)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#include "stdio.h"
#include "stdlib.h"
#include "mqueue.h"
#include "sys/stat.h"
#include "string.h"
#include "time.h"
#define MAX_CHAR 127
#define STR_SIZE 100
void give_string(char *);
int main (void)
{
int status = 0;
mqd_t analyze_q;
char *sent_msg;
struct mq_attr attr;
analyze_q = mq_open("/analyze_q", O_WRONLY, S_IRUSR|S_IWUSR, NULL);
if (0 > analyze_q)
{
perror("mq_open");
exit(1);
}
sent_msg = (char *) malloc (100);
if (NULL == sent_msg)
{
perror("malloc");
exit(1);
}
give_string(sent_msg);
status = mq_getattr(analyze_q,&attr);
status = mq_send(analyze_q,(void *)&sent_msg[0],attr.mq_msgsize,(unsigned)NULL);
free(sent_msg);
status = mq_close(analyze_q);
return(0);
}
void give_string(char *result)
{
int j = 0;
int i = 0;
srand((unsigned)time(NULL));
for (i=0;i<100;i++)
{
result[i] = (char) (1 + (int) (MAX_CHAR * (rand() / (RAND_MAX + 1.0))) );
}
}
|