Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/ipc.h>
- #include <sys/msg.h>
- #include <stdlib.h>
- typedef struct our_msgbuf{
- long mtype;
- char buffer[80];
- } Message;
- int main(){
- Message msg;
- int msgid,key,n;
- if(key=ftok("serv",'A') <0){
- perror("ftok");
- printf("Can't obtaint key\n");
- exit(1);
- }
- msg.mtype=1L;
- if(msgid=msgget(key,0666|IPC_CREAT)<0){
- perror("msgget");
- printf("Can't create IPC\n");
- exit(1);
- }
- printf("%d\n",msgid);
- n=msgrcv(msgid,&msg,sizeof(msg),msg.mtype,0);
- if(n>0){
- if(write(1,msg.buffer,n)!=n){
- printf("Error of output\n");
- exit(1);
- }
- }
- else{
- printf("Error while reading the message\n");
- perror("read");
- }
- exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement