当前位置: 技术问答>linux和unix
创建消息队列,接受消息失败,接受程序再发送错误消息给发送程序//程序能运行,不出结果
来源: 互联网 发布时间:2017-02-01
本文导语: #ifndef BANK_P_H #define BANK_P_H struct account{ int account_id; char account_name[10]; double account_salary; }; struct Bank{ long mtype; struct account account_m; }; struct Message{ long mtype; char message...
#ifndef BANK_P_H
#define BANK_P_H
struct account{
int account_id;
char account_name[10];
double account_salary;
};
struct Bank{
long mtype;
struct account account_m;
};
struct Message{
long mtype;
char message[20];
};
int key = 0x87111;
#endif
#include
#include
#include
#include
#include
#include
#include
#include "bank_p.h"
int msgid;
void init()//create message queue
{
printf("banks' server begins to openedn");
msgid = msgget(key,IPC_CREAT|IPC_EXCL|0666);
if(msgid == -1) msgid = msgget(key,0);
if(msgid == -1) perror("banks'server begins to failed"),exit(-1);
printf("banks'service successfullyn");
}
void service()//receive function
{
printf("banks' server begins to operationn");
printf("stop:ctrl+cn");
struct Bank bank_server;
struct Message message_obj;
message_obj.mtype = 3;
strcpy(message_obj.message,"sorry,can't receive your message comes form linet");
while(1)
{ //can't receive message ,and send error message to linet.
if(msgrcv(msgid,&bank_server,sizeof(struct Bank),1,0)