forked from MeiK2333/apue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp12.c
37 lines (34 loc) · 870 Bytes
/
p12.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
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/msg.h>
int main() {
int i, id;
char *hello = "Hello World!\n";
for (i = 0; i < 5; i++) {
if ((id = msgget(0, IPC_CREAT)) == -1) {
printf("msgget error\n");
exit(1);
}
printf("id = %d\n", id);
if (msgctl(id, IPC_RMID, NULL) == -1) {
printf("msgctl IPC_RMID error\n");
exit(1);
}
}
printf("\n\n");
for (i = 0; i < 5; i++) {
if ((id = msgget(IPC_PRIVATE, 0)) == -1) {
printf("msgget error\n");
exit(1);
}
printf("id = %d\n", id);
if (msgsnd(id, hello, 0, IPC_NOWAIT) == -1) {
printf("%s\n", strerror(errno));
printf("msgsnd error\n");
exit(1);
}
}
exit(0);
}