forked from 834810071/NetworkProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmsgctl01.cpp
More file actions
43 lines (35 loc) · 800 Bytes
/
msgctl01.cpp
File metadata and controls
43 lines (35 loc) · 800 Bytes
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
//
// Created by jxq on 19-8-12.
//
// p25 system v消息队列(一)
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#define ERR_EXIT(m) \
do \
{ \
perror(m); \
exit(EXIT_FAILURE); \
} while (0);
int main(void)
{
int msgid;
msgid = msgget(1234, 0);
if (msgid == -1)
{
ERR_EXIT("msgget");
}
printf("msgget succ\n");
printf("msgid = %d\n", msgid);
struct msqid_ds buf;
msgctl(msgid, IPC_STAT, &buf);
printf("mode = %o\n", buf.msg_perm.mode);
printf("bytes = %ld\n", buf.__msg_cbytes);
printf("number=%d\n", (int)buf.msg_qnum);
printf("msgmnb=%d\n", (int)buf.msg_qbytes);
return 0;
}