-
Notifications
You must be signed in to change notification settings - Fork 0
/
msgfoo.c
60 lines (53 loc) · 1.19 KB
/
msgfoo.c
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
/*
* This program can be used to figure out how large the buffer/limit for a
* message queue is.
*/
#define _XOPEN_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <unistd.h>
struct list_head {
void *prev, *next;
};
/* copied from linux/include/linux/msg.h */
struct msg_msg {
struct list_head m_list;
long m_type;
size_t m_ts; /* message text size */
void *next;
void *security;
/* the actual message follows immediately */
};
int main(void) {
int mq = msgget(IPC_PRIVATE, 0600|IPC_CREAT);
printf("msgget = %d\n", mq);
struct {
long mtype;
char data[0xb8 - 0x30];
} buf = {
.mtype = 0x0102030405060708,
.data = "HELLO WORLD! "
"HELLO WORLD! "
"HELLO WORLD! "
"HELLO WORLD! "
"HELLO WORLD! "
"HELLO WORLD! "
"HELLO WORLD! "
"HELLO WORLD! "
"HELLO WORLD! ",
};
for (int i = 0; i < 0x100000; i++) {
printf("[%4d] msgsnd = ", i);
fflush(stdout);
int ret = msgsnd(mq, &buf, sizeof(buf) - sizeof(long), 0);
printf("%d\n", ret);
if (ret == -1) {
perror("msgsnd");
sleep(1);
}
}
return EXIT_SUCCESS;
}