-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmsg_read.c
More file actions
44 lines (34 loc) · 696 Bytes
/
Copy pathmsg_read.c
File metadata and controls
44 lines (34 loc) · 696 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
44
#include<stdio.h>
#include<stdlib.h>
#include<errno.h>
#include<unistd.h>
#include<sys/wait.h>
#include <string.h>
#include <sys/msg.h>
#include <sys/types.h>
struct my_msgbuf {
long mtype;
char mtext[200];
};
int main(void){
struct my_msgbuf buf;
int msqid;
key_t key;
if( (key = ftok("msg_queue.c",'B')) == -1){
perror(" error in ftok() \n");
exit(1);
}
if ( (msqid = msgget(key, 0644)) == -1){
perror("Error in getting msgget() \n");
exit(2);
}
printf("Reader is ready \n");
while(1){
if(msgrcv(msqid,&buf,sizeof buf.mtext,0,0) == -1){
perror(" error in reading message \n ");
exit(3);
}
printf("Message received is %s \n", buf.mtext);
}
return 0;
}